Evaluate a simple Python expression -
i'm experimentig simple things in python , have different result when write same things in 2 different ways.
(ord(x) + ^ ord(y[i])) % 255
i want expression equal example 57, since 5 ^ ord(y[5]) = 114
(with i=5 , y[i]='w').i thought since 114+198=312
, 312%255=57
ord(x) should 198, if write on python console:
(ord(chr(198)) +5^ord(y[5])) % 255
188.
instead if write:
(ord(chr(73)) +5^ord(y[5])) % 255
want: 57
am missing somethings obvious here? why way of thinking wrong?
working simpler case:
>>> 1 + 1 ^ 1 3
if want xor done first, need put parentheses around it, like
(ord(x) + (i ^ ord(y[i]))) % 255
Comments
Post a Comment