You are on page 1of 1

#include<iostream>

#include<math.h>
using namespace std;
int main()
{
int b,x,k;
int g=0;
cout<<"enter a 8 bit binary number";
cin>>b;
x= pow(10,7);
if(b/x==1)
{
int r=b%x;
for(int i=0;i<7;i++)
{
int c=r%10;
if(c==1)
c=0;
else
c=1;
r=r/10;
int f= pow(2,i);
k=k+c*f;
}
cout<<"-"<<k+1;
}
if(b/x!=1)
{
for(int i=0;i<8;i++)
{
int c=b%10;
b=b/10;
int f= pow(2,i);
g=g+c*f;
}
cout<<g;
}
return 0;

You might also like