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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -