penguru
penguru

Reputation: 4370

string to hex value

Is there any java utility to convert string to hex value (integer) ?

Upvotes: 5

Views: 16548

Answers (4)

jwoolard
jwoolard

Reputation: 6284

Try some of the methods of the Integer class:

Integer.toHexString(Integer.parseInt(myString, 10))

This assumes that your original string is an integer base ten.

Upvotes: 1

AlbertoPL
AlbertoPL

Reputation: 11509

Is this what you are looking for?

Integer.toHexString(Integer.parseInt(String));

Upvotes: 4

Markus Lausberg
Markus Lausberg

Reputation: 12257

When you have a string starting with 0x or #

Integer.decode(hexStr);

is the goal

Or

Integer.parseInt(hexString, 16);

Upvotes: 14

Brian Agnew
Brian Agnew

Reputation: 272277

Your question is a little ambiguous, I think.

If you have a hex string (e.g. "ab10"), then you can use

int i = Integer.valueOf(s, 16).intValue();

Upvotes: 3

Related Questions