Python Node.js character manipulation

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

Python Node.js character manipulation
Python Grammar-String Manipulation
python character code
Python list manipulation
String manipulation in python
Date manipulation in Python
Python string manipulation master
About Python3 character code
Manipulating Python character lists (arrays)
3-3, Python strings and character codes
2.x, 3.x character code of python
Regular expression manipulation with Python
String date manipulation in Python
Character code learned in Python
Python f character (formatted string)
Today's python error: SyntaxError Non-ASCII character
Pixel manipulation of images in Python
File / folder path manipulation in Python
Python
[Beginner] Extract character strings with Python
[Introduction to Udemy Python3 + Application] 13. Character method
Python UTC ⇔ JST, character string (UTC) ⇒ JST conversion memo
I made a character counter with Python
# 5 [python3] Extract characters from a character string
[Python] How to invert a character string
[Python beginner memo] Python character string, path operation
[Introduction to Udemy Python3 + Application] 11. Character strings
[Python] Chapter 04-02 Various data structures (list manipulation)
Basic grammar of Python3 system (character string)
[Python] Chapter 04-07 Various data structures (dictionary manipulation)
Let's do MySQL data manipulation with Python
[Python] Get the character code of the file
Python basic course (4 numeric type / character string type)
When Python "Syntax Error: Non-ASCII character ~" appears