K
K
kuzdman2018-10-04 20:46:51
Python
kuzdman, 2018-10-04 20:46:51

Why ord("B") = 66 and not 42 in python?

Guys, you need to convert text to hexadecimal code via ord() in python.
Why ord("B") = 66 and not 42?
For example,
"Bill Gates" --> "42 69 6c 6c 20 47 61 74 65 73" ( it should be ).
And I get "66 105 108 108 32 71 97 116 101 115" .
Where is the mistake?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SagePtr, 2018-10-04
@kuzdman

Because you output in decimal notation?

I
igorzakhar, 2018-10-04
@igorzakhar

>>> s = "66 105 108 108 32 71 97 116 101 115"
>>> x = [format(int(i), 'x') for i in s.split()]
>>> ' '.join(x)
'42 69 6c 6c 20 47 61 74 65 73'
>>>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question