-3

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.

John Doe
  • 91
  • 1
  • 3
  • 9
  • 3
    Search for hexadecimal notation. – Johnny Mopp Nov 08 '18 at 17:16
  • Stackoverflow is not a human driven Search engine. Please consider doing at least a tiny bit of research before asking such basic questions. Googling for "Numbers with 0x" gives several examples. – Yastanub Nov 08 '18 at 17:20

2 Answers2

2

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

pm100
  • 42,706
  • 22
  • 76
  • 135
1

'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.

Linny
  • 750
  • 1
  • 7
  • 21