I want to work in binary for some aspects of my programming but I can't find anything on binary for C. Such as in a PRINTF statement I want to display a variable as a binary number. From what I have found you can only display as a decimal, hex or octal numbers. Anyone have any ideas??
Thanks
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
Posted: Thu Feb 19, 2009 1:38 pm
Code:
//=== display_binary ===//
void display_binary(char c){
int8 i=7;
putc('0');
putc('b');
do
{
if( c & 0x80 ) putc('1');
else putc('0');
c <<= 1;
} while(i--);
}
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum