Very short rundown.
First, bf
is an uninitialised global variable. This means it will end up in the .bss
segment, which is typically zero-initialised on startup (although you can pass -fno-zero-initialized-in-bss
to GCC to stop this, not sure about MSVC, and of course it depends on your crt0
). This explains the value of f8
, since you haven't written to it.
f1
is 1. You assign it 1. That one's obvious. Same with f2
(since hex 3 is dec 3).
f4
is because the field for f4 is only 4 bits wide. 0xFF
is an 8 bit pattern which is all ones, which is then truncated to 4 bits, and is hence 15 (the highest value that can be represented with 4 bits).
f5
is due to a signed/unsigned conversion. The 5-bit two's compliment representation of -4 is 11100. If you interpret that value as unsigned (or rather, just a plain binary -> decimal conversion), you get 28.
f6
is 63 because of an octal conversion. Any C literal number beginning with a zero is treated as octal. Octal 377 is decimal 255 (which is 11111111 in 8-bits), which is then truncated to 6 bits, leaving 111111
. This is 63.