Doing a bitwise operation on bytes

后端 未结 3 1835
悲&欢浪女
悲&欢浪女 2021-01-04 02:21

I got two objects, a and b, each containing a single byte in a bytes object.

I am trying to do a bitwise operation on this to get the two m

3条回答
  •  佛祖请我去吃肉
    2021-01-04 03:18

    A more general answer

    def andbytes(abytes, bbytes):
        return bytes([a & b for a, b in zip(abytes[::-1], bbytes[::-1])][::-1])
    

    Though IMO pyhon bytes objects should aready do this....

提交回复
热议问题