Hi :)
I am reading a tutorial where the guy labels some flags in hex
Flag1=0x000001;
Flag2=0x000002;
Flag3=0x000003;
He then says
" Now, notice how we have them numbered in hex. This is because we're treating the Flags in binary. This way, we can activate multiple flags at once"
I don't understand this, because surely the binary is the same even
if you use 1,2,3,4.... I just can't figure out what the advantage is
he is talking about. Can anyone shed some light? Cheers!
Hex is good when working with flags/binary because they line up so that one hexadecimal digit is 4 bits. It is easy to see that 0x23 is 0010 0011 in binary. It is not as easy if written as decimal 35. For small numbers < 8 it doesn't matter if you use hexadecimals but you might want to use it anyway for consistency.
Note that in your example flag3 has both bit 1 and bit 2 set. If the intention is to have bit 3 set you should use 0x000004.