Results 1 to 8 of 8
- 02-15-2010, 08:28 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 29
- Rep Power
- 0
How to convert a String into an Hexadecimal ?
Hi!
I have a String which represents a hexadecimal number (e.g. "5FA2"). Ideally, I would like to convert this String into an int (e.g. 0x5FA2), is there a quick way to do this ?
I can't use the method "Integer.parseInt()" since my String represents an hexadecimal and not a decimal.
Thanks in advance!
- 02-15-2010, 08:35 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Read the API specs for the Integer class. There is another Integer.parseInt method that you will find interesting.
- 02-15-2010, 08:36 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
- 02-15-2010, 12:33 PM #4
Member
- Join Date
- Feb 2010
- Posts
- 29
- Rep Power
- 0
Thanks guys!
Looks like the method Integer.decode() is working :-)
- 02-15-2010, 01:50 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
decode( ... ) gives you an Integer, not an int; auto(un)boxing will help you but still an additional Integer object was created (ignoring the fact of caching some Integers here). Better use the overloaded parse( ... ) method. Read the API documentation for the Integer class (again).
kind regards,
Jos
- 02-15-2010, 02:42 PM #6
Member
- Join Date
- Feb 2010
- Posts
- 29
- Rep Power
- 0
Sorry, I just missed this other parse method.
Indeed, that works even better, saves 1-2 lines :-)
Thanks again JosAH!
- 02-15-2010, 05:09 PM #7
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 02-16-2010, 10:31 PM #8
Member
- Join Date
- Feb 2010
- Posts
- 29
- Rep Power
- 0
Similar Threads
-
trying to convert an interger to a string
By matpj in forum New To JavaReplies: 12Last Post: 01-15-2009, 10:08 AM -
convert a really big string (len 39) to bigdecimal
By coolsig in forum Advanced JavaReplies: 6Last Post: 06-14-2008, 02:48 AM -
How to convert integer to the hexadecimal and octal number
By Java Tip in forum java.langReplies: 0Last Post: 04-06-2008, 07:40 PM -
How do I convert a decimal value to hexadecimal with double precision (64 bit)
By SKaur in forum New To JavaReplies: 7Last Post: 01-12-2008, 09:02 PM -
convert string to a double?
By javaMike in forum Advanced JavaReplies: 2Last Post: 11-27-2007, 03:10 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks