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

1

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you :) I would give U +1 but I haven't got enough reputation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.