This has been bugging me for the last few hours. I have a long string and I want to convert it to a byte array. I want to preserve leading zeroes too. Have tried DatatypeConverter & BigInteger methods and cant seem to get the proper result. which is a byte array (of hex byte values).
byte[] array = str.getBytes();
This also doesn't seem to work, with all these methods I seem to be getting decimal representation of the string. I need it to be hex.
This is what I'm using at the minute:
String line;
line = file.readLine();
long seq = Long.parseLong(line);
String hexx = Long.toHexString(seq);
byte[] out = hexx.getBytes();
BTW, i am using BufferdReader for input and RandomAccessFile for output. Any help would be appreciated.
0s are disappearing cause ofLong.parseLong()12345, what should the byte representation be? Something like[0x01, 0x02, 0x03, 0x04, 0x05]?