aspose file tools*
The moose likes Beginning Java and the fly likes Literals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Literals" Watch "Literals" New topic
Author

Literals

Adi Sharma
Ranch Hand

Joined: May 18, 2009
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.

Help please

Thnks
Aditya Sharma
Faisal Ansari
Ranch Hand

Joined: Jun 23, 2009
Posts: 36
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
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
Aditya Sharma
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

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).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Adi Sharma
Ranch Hand

Joined: May 18, 2009
Posts: 33
Thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Literals