<< so the only other way I know of is to convert the Hex into Decimal and then convert the Decimal to Binary. >>
Hmm? Convert hex into decimal, then to binary? Any given numeric value can be /represented/ in hex, or decimal, or octal, ad nauseum. If an numeric value is represented in hex, it's still a number. If it's represented in decimal, it's still the same number. Binary is just another representation, there's no need to convert between any of the bases. Indeed, when you represent a number in hex, then in decimal, you aren't converting anything. Here's an example of how you would print the binary representation of a byte...
char x = 1;
int n;
for(n=0; n<8; n++)
{
if((x & 0x80) !=0)
{
printf("1");
}
else
{
printf("0");
}
if (n==3)
{
printf(" ");
}
x = x<<1;
}
It'll put a space between the nibbles (a nibble is 4 bits). A little explanation of how it works:
Lets say the byte (x) is numeric 1 (lets keep it simple). x, in binary, would look like...
0000 0001
In the for loop you see, n starts out at 0, and goes to 7. So, in the first iteration of the loop, n, in binary, looks like...
0000 0000
It will bitwise AND x with 0x80. 0x80 in binary looks like...
1000 0000
So, 00000000 AND 10000000 == 0, so it will print a 0 (as it should). It will then shift x left on bit position, giving you...
0000 0010
The bitwise AND will still == 0 as 00000010 AND 10000000 == 0. It will keep shifting left until it's reached the byte boundary. When n == 7, x will have been shifted giving you...
x = 10000000
ANDing x with 0x80 gives you 10000000 AND 10000000 == 255 (i.e. >0), so it'll print a 1. The result should be 0000 0001, which is what you wanted.
Hope that made sense.