Meaningless Drivel is fun!
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

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Reg. Integer literals" Watch "Reg. Integer literals" New topic

Reg. Integer literals


Joined: Jun 08, 2000
Posts: 28
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).

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

Joined: Nov 22, 2008
Posts: 18944
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
[This message has been edited by rahul_mkar (edited June 08, 2000).]
Jakob Bosshard

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;
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));
Finally you can parse an int from a string giving the radix you want to use:
int j = Integer.parseInt("FF", 16);
//output is 255
Just write some code with the java.lang.Integer class and find
out about all the representations.
Hope this will help

Joined: Jun 08, 2000
Posts: 28
Ya!!!Now Iam clear.
Thanks Guys.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Reg. Integer literals
It's not a secret anymore!