Hi I have the following string
String msg = "9192939495"
And i want to create the bellow byte
byte[] texttoprint = {(byte) 0x91, (byte) 0x92,(byte) 0x93,(byte) 0x94,(byte) 0x95}
i try this
public static byte[] hexStringToByteArray(String s) {
/*String input = "0102FFAB";*/
byte[] data = new byte[s.length() / 2];
for( int i = 0; i < s.length(); i+=2)
{
data[i/2] = (byte) Integer.decode( "0x" + s.substring( i, i + 2 ) ).byteValue();
}
return data;
}
but it does not works
Also how can I print texttoprint at eclipse log in order to check if everything is OK?
PS if i send to printer {(byte) 0x91, (byte) 0x92,(byte) 0x93,(byte) 0x94,(byte) 0x95} everything is OK but if i sent the result of hexStringToByteArray nothing happens
Arrays.toString
to converttexttoprint
into a text representation – oldrinb Sep 9 '12 at 16:45