-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
  • 4,294
  • 5
  • 22
  • 55

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
  • 127,356
  • 13
  • 118
  • 231
dbush
  • 186,650
  • 20
  • 189
  • 240