Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# Literals

Ranch Hand
Posts: 33
HI,

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.

Thnks

Faisal Ansari
Ranch Hand
Posts: 36
try putting a prefix 0 before the octal number and 0x before the hexadecimal number...

Ranch Hand
Posts: 33
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 .

Please correct me if I am wrong.

Thanks

Rob Spoor
Sheriff
Posts: 20709
68
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).

Ranch Hand
Posts: 33
Thanks a lot