Ben
Ben

Reputation: 361

Use python string as byte

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

Answers (2)

x3l51
x3l51

Reputation: 731

ord('H')
chr(72)

Its as simple as that. Remember that chr() only takes int and ord() only takes str

Upvotes: 1

Harshil Shah
Harshil Shah

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

Related Questions