Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string to hex value

Tags:

java

string

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

like image 981
penguru Avatar asked Jul 08 '09 12:07

penguru


People also ask

Can we convert a string to hex?

Initialize final Hex string as empty. Consider every character from input, cast it into integer. This integer value is ascii value of that character. Change this integer value into hexadecimal value and add this hexadecimal value to final Hex string.

How do I encode a hex string?

Hex encoding is performed by converting the 8 bit data to 2 hex characters. The hex characters are then stored as the two byte string representation of the characters. Often, some kind of separator is used to make the encoded data easier for human reading.

Can you convert string to hex in python?

Using the int() function: Using int(string, base=16) , we can convert the string to an integer with base 16 (Hexadecimal). Once we have the integer, we can use the inbuilt hex() function to convert an integer to a Hexadecimal number.


2 Answers

When you have a string starting with 0x or #

Integer.decode(hexStr);

is the goal

Or

Integer.parseInt(hexString, 16);
like image 131
Markus Lausberg Avatar answered Sep 20 '22 04:09

Markus Lausberg


Is this what you are looking for?

Integer.toHexString(Integer.parseInt(String));
like image 43
AlbertoPL Avatar answered Sep 19 '22 04:09

AlbertoPL