?
2014-10-16 13:33:58 UTC
if i insert 150 after i run im expecting to get this
1 0 0 1
but im getting 1 0 0 0
why ?
#include "stdafx.h"
#include "iostream"
using namespace std;
int main()
{
int a=128 ,b=64 ,c=32 ,d=16 ,e=8 ,f=4 ,g=2 ,h=1 ,x ,m ,l ,i ,k ,j;
cout << "type a number to convert from decimal to binary" ;
cin >> x;
if (x>=a)
{
cout <<" 1 " ;
l=x-a ;
}
else
{
cout << " 0" ;
x=l;
}
if (l>=b)
{
cout<<" 1" ;
i=l-b ;
}
else
{
cout << " 0" ;
l=i ;
}
if (i>=c)
{
cout<<" 1" ;
j=i-c ;
}
else
{
cout << " 0" ;
i=j ;
}
if (j>=d)
{
cout <<" 1" ;
k=j-d ;
}
else
{
cout << " 0" ;
j=k;
}
cout << " " << k << endl;
cin >> m ;
return 0;
system("pause");
}