aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes fundamentals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "fundamentals" Watch "fundamentals" New topic
Author

fundamentals

swarna kumar
Greenhorn

Joined: Nov 11, 2001
Posts: 17
hi guys,
examine th code,
class demo{
public static void main(String args[]){
int i=012;
System.out.println(i);
}
}
the result gives 10, why so? and how?,give the full details.
thx
swarna
[LIST]
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Any integer literal prefixed by 0 is interpreted to be an octal. 012 is 1 x 8^1 + 2 x 8^0 = 8 + 2 = 10.
swarna kumar
Greenhorn

Joined: Nov 11, 2001
Posts: 17
thx anthony,now i got it.
swarna
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Java has three types of integer literals:
- decimal: 123, 345, 3764632, ...
- octal: 012, 0345, 076, 012, ...
- hexadecimal: 0xF4E3, 0XABDC, 0x0254, ...
Note that:
- decimal literals are composed of digits from 0 to 9 where the left-most digit cannot be 0.
- octal literals always begin with a 0 followed by digits ranging from 0 to 7
- hexadecimal literals always begin with 0x (zero lowercase x) or 0X (zero uppercase x) followed by digits ranging from 0 to 9 and letters ranging from A to F (upper- or lowercase letters)
[ July 11, 2002: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
zarina mohammad
Ranch Hand

Joined: Jun 26, 2002
Posts: 104
how to convert Hexadecimal to decimal?
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

You convert hexidecimal to decimal the same way you convert octal to decimal:
0132 is (1 x 8^2) + (3 x 8^1) + (2 x 8^0) = 64 + 24 + 2 = 90 (octal)
0x132 is (1 x 16^2) + (3 x 16^1) + (2 x 16^0) = 256 + 48 + 2 = 306 (hexidecimal)
[ July 12, 2002: Message edited by: Jessica Sant ]

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
zarina mohammad
Ranch Hand

Joined: Jun 26, 2002
Posts: 104
Thanks Jess ,that was helpful.
swarna kumar
Greenhorn

Joined: Nov 11, 2001
Posts: 17
thx valentin and jess,
thx for good explanation,
swarna
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: fundamentals