Reputation: 361
I have the byte representation of a character in a string, let's say the character is 'H', which has the byte value of 72. My string is therefore "72".
How do I go about converting this string ("72") into its corresponding character value ('H') based on the byte value (72) represented in my string using python 3.6?
Psuedo code:
str = 72
print(decode_as_byte_value(str))
Expected result:
H
Upvotes: 0
Views: 57
Reputation: 731
ord('H')
chr(72)
Its as simple as that. Remember that chr() only takes int and ord() only takes str
Upvotes: 1
Reputation: 152
Please do not use this community for such Syntex based questions.
Still your ans is:
# Get the ASCII number of a character
number = ord(char)
# Get the character given by an ASCII number
char = chr(number)
If this is your answer tick mark this response.
Upvotes: 1