S
scrodchunk
I'm having a weird problem with printing bytes in hex format.
I have a bunch of print statements that are working okay, then using
the identical formatting later in my code I get some thing where the
formatting and type are ignored.
At one spot in my code I'm loading an array with random bytes
int i;
char byte_block[20];
for (i=0; i<20; i++)
byte_block = (char) rand()
then elsewhere:
for (i=0; i<20; i++)
printf(" heres a byte: %2.2X \n", byte_block);
rand() returns a random integer, but I'm casting it to a char, which
should give me a single byte
when I print out various elements of the array byte_block, I often get
a number much bigger than a byte (it's 4 bytes)
For some reason I get:
00 FFFFFFB3 77 FFFFFF82 FFFFFFAC 22 37 63 FFFFFFD6 74
77 FFFFFFBD FFFFFFED 09 30 FFFFFFC9 FFFFFFC4 FFFFFFE9 7C 61
(my extra cr/lfs)
Why are some prints nice 2 digit bytes and others have 6 F's? What am
I missing.
Elsewhere in my code I'm doing the same thing and get a nice string of
2digit bytes.
Even when I do this:
printf(" heres a byte: %2.2X \n", (char)byte_block[3]);
I get FFFFFF82. The format and the cast are being ignored??
Confused on a friday evening,
Ross
I have a bunch of print statements that are working okay, then using
the identical formatting later in my code I get some thing where the
formatting and type are ignored.
At one spot in my code I'm loading an array with random bytes
int i;
char byte_block[20];
for (i=0; i<20; i++)
byte_block = (char) rand()
then elsewhere:
for (i=0; i<20; i++)
printf(" heres a byte: %2.2X \n", byte_block);
rand() returns a random integer, but I'm casting it to a char, which
should give me a single byte
when I print out various elements of the array byte_block, I often get
a number much bigger than a byte (it's 4 bytes)
For some reason I get:
00 FFFFFFB3 77 FFFFFF82 FFFFFFAC 22 37 63 FFFFFFD6 74
77 FFFFFFBD FFFFFFED 09 30 FFFFFFC9 FFFFFFC4 FFFFFFE9 7C 61
(my extra cr/lfs)
Why are some prints nice 2 digit bytes and others have 6 F's? What am
I missing.
Elsewhere in my code I'm doing the same thing and get a nice string of
2digit bytes.
Even when I do this:
printf(" heres a byte: %2.2X \n", (char)byte_block[3]);
I get FFFFFF82. The format and the cast are being ignored??
Confused on a friday evening,
Ross