DEV Community

Cover image for Dealing with integer by different radix
Yasushi Takehara
Yasushi Takehara

Posted on

Dealing with integer by different radix

In Java, numbers can be written by various radix.

// radix 10
int value = 255;

// radix 16
value = 0xff; // starts from 0x
value = 0xFF; // ff can be written as upper case, but not common
value = 0Xff; // x can be upper case, but not common

// radix 8
value = 0377; // starts from 0

// radix 2
value = 0b11111111; // starts from 0b
value = 0b1111_1111; // under score can be put for separation
Enter fullscreen mode Exit fullscreen mode

These are all same values essentially and given for convenience for programmers when reading.

Reference
https://gihyo.jp/book/2014/978-4-7741-6685-8

Top comments (0)