This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Reg. Integer literals

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya!!!Now Iam clear.
Thanks Guys.
 
Why fit in when you were born to stand out? - Seuss. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic