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

# Reg. Integer literals

Sunita
Greenhorn
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
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
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
Hope this will help
Regards
Jakob

Sunita
Greenhorn
Posts: 28
Ya!!!Now Iam clear.
Thanks Guys.