I was reading that "You can have up to 21 digits in an octal number and 16 digits in an hexadecimal number " ,But when I tried it, it says type int out or range.

try putting a prefix 0 before the octal number and 0x before the hexadecimal number...

SCJP 6

Adi Sharma
Ranch Hand

Joined: May 18, 2009
Posts: 33

posted

0

I think that the answer is that if you declare the variables of type 'long' and not 'int', then the octal value can have 21 digits and hexadecimal can have 16 digits. But if you use 'int', then it turns out to be out of 'int' range .

Long.MAX_VALUE is 0x7FFFFFFFFFFFFFFF, so 16 characters (excluding the 0x), and 0777777777777777777777, so 21 characters (excluding the leading 0). So yes, these limits hold for long.

Integer.MAX_VALUE is 0x7FFFFFFF (8 characters) and 017777777777 (11 characters).