#include <iostream>
usingnamespace std;
int x1;
int x2;
int x3;
int x4;
int x5;
int x6;
int x7;
int x8;
int main()
{
//128 64 32 16 8 4 2 1
int a;
cin>> a;
cout<< endl;
if(a<=128){x1=0;}
elseif (a>=128){x1=1; a=a-128;}
if (a<=64){x2=0;}
elseif (a>=64){x2=1; a=a-64;}
if(a<=32){x3=0;}
elseif (a>=32){x3=1; a=a-32;}
if(a<=64){x4=0;}
elseif (a>=16){x4=1; a=a-16;}
if(a<=8){x5=0;}
elseif (a>=8){x5=1; a=a-8;}
if(a<=4){x6=0;}
elseif (a>=4){x6=1; a=a-4;}
if(a<=2){x7=0;}
elseif (a>=2){x7=1; a=a-2;}
if(a<=1){x8=0;}
elseif (a>=1){x8=1; a=a-1;}
cout<< x1 << x2 << x3 << x4<< x5 << x6 << x7 << x8 << endl;
}
It doesn't seem to work at all, it gives the wrong answers. For example, when I type in 78, it gives 01001101, which is wrong. (78 in binary is 1001110)