Convert both Python and Node.js in the following order Hexagonal character string ⇔ Binary ⇔ Character string ⇔ Unicode (decimal number) ⇔ Hexographic number character string And the default encoding is UTF-8 Python
str_data = "Ah"
encoded = str_data.encode() #b'\xe3\x81\x82'
hex_str = encoded.hex() #"e38182"
encoded = bytes.fromhex(hex_str) #b'\xe3\x81\x82'
str_data = encoded.decode() #"Ah"
unicode = ord(str_data) #12354
sixteen = hex(unicode) #'0x3042'
unicode = int(sixteen,16) #12354
str_data = chr(unicode) #"Ah"
Node.js
let strData = "Ah";
let encoded = Buffer.from(strData); //<Buffer e3 81 82>
let hexStr = encoded.toString("hex"); //"e38182"
encoded = Buffer.from(hexStr,"hex"); //<Buffer e3 81 82>
strData = encoded.toString(); //"Ah"
let unicode = strData.codePointAt(0); //12354
let sixteen = unicode.toString(16); //'0x3042'
unicode = parseInt(sixteen,16); //12354
strData = String.fromCodePoint(unicode); //"Ah"
Recommended Posts