-1

I have unsigned 16-bit number that I need to print in hexadecimal to the terminal like this:

0x0FFE

But using printf("0x%X\n", number"); I'm get this:

0xFFE

Is there way to fully print number in hexadecimal on C or C++?

OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87

1 Answers1

2

By default, leading zeros are not printed. To print at least 4 characters with leading zeros, use the 0 flag and a field width of 4.

printf("0x%04X\n", number);
chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
dbush
  • 205,898
  • 23
  • 218
  • 273