2

An Item-ID in hexadecimal and the amount in decimal has to be entered in two JTextFields.

Now I have to convert the Item ID hexadecimal encoded in a String to a byte hexadecimal.

String str = itemIdField.getText(); // Would be, for example, "5e"
byte b = // Should be 0x5e then.

So if str = "5e", b = 0x5e

if str = "6b" b = 0x6b and so on.

Does anybody now, what the code to convert that would be then? Google doesn't know, it thinks, I want to convert the text to a byte[]

Thank you, Richie

KeksArmee
  • 1,349
  • 14
  • 21

1 Answers1

4

You can use Byte.parseByte(str, 16), that will return the byte value represented by the hexadecimal value in str.

tofcoder
  • 2,352
  • 1
  • 20
  • 28