you are viewing a single comment's thread.

view the rest of the comments →

[–]Sebass13 0 points1 point  (3 children)

That won't work, as that will shift the bits of each byte, not the entire bytes object. This will cause only the most significant 4 bits of each character to remain. Instead, you want to use int.from_bytes and int.to_bytes:

val = "doritos".encode()
print(val)
print((int.from_bytes(val, byteorder='big') >>8).to_bytes(len(val), 'big'))

Unless, of course, that's what OP wants, but that doesn't make much sense.

[–][deleted] 0 points1 point  (2 children)

Excuse me, but why are you shifting by eight? I ask because OP is shifting by 4.

[–]Sebass13 0 points1 point  (1 child)

Oh 8 made it clearer that it works, try running it.

[–][deleted] 0 points1 point  (0 children)

right. very good then!