Suppose I was trying to create a mask in C for bitwise operations, like
uint32_t Mask = 0x00000003;
What does the x mean? I see a lot of numbers written with that 0x format and I don't understand why and have been unable to find an explanation that really makes sense to me, maybe I'm not searching the right thing.
'0x' means that the number that follows is in hexadecimal. It's a way of unambiguously stating that a number is in hex, and is a notation recognized by C compilers and some assemblers.
it means the the number is expressed in hex , base 16 instead of decimal, based 10. For your example it makes no difference
uint32_t Mask = 0x00000003;
since 3 is 3 in both bases
but
uint32_t Mask = 0x00000010; // '16' in human talk
is quite different from
uint32_t Mask = 00000010; // '10' in human talk
You will see
uint32_t Mask = 0x00000003;
when expressing something where the value is a set of bit flags rather than a number (see the name 'mask') since hex maps nicely to a sequence of bits. You might see
uint32_t Mask1 = 0x00000003;
uint32_t Mask2 = 0x00000010;
uint32_t Mask3 = 0x000000C2;
The first one doesnt need 0x but it just looks cleaner
User contributions licensed under CC BY-SA 3.0