Friday, March 26, 2010

Display bits of signed numbers

int main()
{
int a=-3,i=0,j;
int b[32];
clrscr();
printf("%d\n",a);
for(j=0;j<32;j++)
b[j]=0;
i=0;
while(a!=0)
{
if(a&01)
{
b[i]=1;
}
else
{
b[i]=0;
}
i++;
a>>=1;
}
for(j=31;j>=0;j--)
{
printf("%d",b[j]);
}
getch();
return 0;
}

0 comments:

Post a Comment