-1

Can someone explain the underlying mechanics behind this chunk of code.

System.out.println(0x10);

3 Answers3

0

0x or 0X in front of the numbers are hex format.

Why 16:

0x1          0

  1 * 16^1 + 0 * 16^0
= 1 * 16   + 0 * 1 
= 16       + 0 
= 16
0

This is a hex number and in decimal it is 16

Jurgiele
  • 95
  • 1
  • 10
0

The 0x indicates the compiler that the following literals are supposed to be a hex number witch in your example is 10 hex or 16 decimal

tung
  • 719
  • 2
  • 14
  • 30