aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Reg. Integer literals 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 "Reg. Integer literals" Watch "Reg. Integer literals" New topic
Author

Reg. Integer literals

Sunita
Greenhorn

Joined: Jun 08, 2000
Posts: 28
Hi,
I would likt know how to convert numbers from hexadecimal format to decimal and Vice versa.
For ex:
int i=0xf;
then the value of i in decimal format is 15.(This is clear).

But
if int i=0xff or i=0xffe
then what's the value of i in decimal format?
Regards
Sunita
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hi,
to convert an integer to Hex use Integer.toHexString(int i).
progamatically i am waiting for someone to tell how to convert form HexString to int.
if u want to do it manually search this site saying 0x as the keyword and u will find lots of pages one of which is
http://www.javaranch.com/ubb/Forum24/HTML/001272.html
http://www.javaranch.com/ubb/Forum24/HTML/000495.html
Rahul
[This message has been edited by rahul_mkar (edited June 08, 2000).]
Jakob Bosshard
Greenhorn

Joined: May 30, 2000
Posts: 21
Hi Sunita
The hexadecimal representation is for the convenience of the
programmer for assignment and output. Internally ints are stored as bytes (binary). Two things on changing the representation:
int i = 0xFF;
System.out.println(i);
This will display the int as a decimal.
The wrapper class java.lang.Integer offers a few conversion methods (mostly static) that allow you to output the Integer in any of the representations returning a string.
int i = 10;
String s = new String(Integer.toHexString(i));
System.out.println(s);
Finally you can parse an int from a string giving the radix you want to use:
int j = Integer.parseInt("FF", 16);
System.out.println(j);
//output is 255
Just write some code with the java.lang.Integer class and find
out about all the representations.
Hope this will help
Regards
Jakob
Sunita
Greenhorn

Joined: Jun 08, 2000
Posts: 28
Ya!!!Now Iam clear.
Thanks Guys.
 
jQuery in Action, 2nd edition
 
subject: Reg. Integer literals