Writing string to byte array in java -
Writing string to byte array in java -
this has been bugging me lastly few hours. have long string , want convert byte array. want preserve leading zeroes too. have tried datatypeconverter & biginteger methods , cant seem proper result. byte array (of hex byte values).
byte[] array = str.getbytes();
this doesn't seem work, these methods seem getting decimal representation of string. need hex.
this i'm using @ minute:
string line; line = file.readline(); long seq = long.parselong(line); string hexx = long.tohexstring(seq); byte[] out = hexx.getbytes();
btw, using bufferdreader input , randomaccessfile output. help appreciated.
ok, convert 1 radix another. jeez!
string str = ... int fromradix = ... int toradix = ... string out = new biginteger(str, fromradix).tostring(toradix);
for example, convert decimal number "12345" hex:
string str = "12345"; int fromradix = 10; int toradix = 16; string out = new biginteger(str, fromradix).tostring(toradix); // yields "3039"
go away! :p
java
Comments
Post a Comment