java - converting Japanese characters to hex not working -
my code simple (using commons-codec-1.10.jar)
system.out.println(hex.encodehex("三菱グループ".getbytes(standardcharsets.utf_8), true));
it yields e4b889e88fb1e382b0e383abe383bce38397 in pc, in accoridng http://codebeautify.org/string-hex-converter, should 4e0983f130b030eb30fc30d7. missing anything?
hex.encodehex
working fine, results utf-8 encoding, whereas codebeautify.org appears using utf-16.
let's take 三 start with. that's u+4e09. in utf-16 that's encoded 4e 09, matches start of codebeautify output. in utf-8 it's encoded e4 b8 89, matches java output.
if want utf-16, use standardcharsets.utf_16be
instead of standardcharsets.utf_8
. (but if really want utf-16. utf-8 better encoding use in cases, imo.)
Comments
Post a Comment