Hexadecimal Output in C

Level 254 keystrokes

Prints the number 255 in decimal with %d and in uppercase hexadecimal with %X: "Dec: 255, Hex: FF".

C code

// 255 = 15 * 16 + 15, and 15 is the hex digit F, so 255 is FF in hexadecimal
1int num = 255;
// The same value is printed twice: %d as decimal, %X as uppercase hex (%x would give ff)
2printf("Dec: %d, Hex: %X\n", num, num);

Output

Dec: 255, Hex: FF
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C code and how often they appear.

  • ,× 3
  • ;× 2
  • :× 2
  • "× 2
  • %× 2
  • (× 1
  • )× 1
  • \× 1
  • =× 1

More C examples at level 2

← C typing practice