2021年4月30日星期五

How to cast bytes to an int and back to the same bytes?

I have an arbitrary byte in Python that I want to cast into a 64 bit integer and back into the same byte.

I am currently, using this to turn the bytes into an int, where x is a byte I am given:

int.from_bytes(x, "little")  

But I'm struggling on how to use int.to_byte() to convert it back to the same bytes because I'm unsure what to put for length, nothing seems to create the equivalent byte?

https://stackoverflow.com/questions/67341565/how-to-cast-bytes-to-an-int-and-back-to-the-same-bytes May 01, 2021 at 07:34AM

没有评论:

发表评论