Tuesday, March 15, 2011

binary format display

#include "stdio.h"
int a, b, c, d, e;
void main()
{
int i;
a = 65;
b = 0x41;
c = 'A';
d = 'A'+3;

printf("a = %d b = %d c = %d\n", a, b, c);

printf("Ascii %c, decimal %d, hex %02x\n", d, d, d);

printf("Here is d in binary: ");
for(i = 7; i>=0; i--) {
if((1<<i)&d)
printf("1");
else
printf("0");
}
printf("\n");
}

No comments:

Post a Comment