1

How do I convert string value of a hexadecimal to be used as a byte. For example, I get the hexadecimal string value through -

 String strVal = String.format("%02x", buf[i]); //lets say it is "3D"

Now I want to convert that into a byte, so I can do something like this

byte bVal =  0x[value?] //0x3D; 

Thanks

San Mor
  • 133
  • 2
  • 12

2 Answers2

0
String hex = ...;
int temp = Integer.parseInt(hex , 16);

byte result = (byte) temp;
0

You can use getBytes().So strVal.getBytes().