How to reverse bits of a byte?

前端 未结 8 2356
广开言路
广开言路 2021-02-09 13:09

For example, in PHP, how would I reverse the bits of the byte 11011111 to 11111011?

8条回答
  •  深忆病人
    2021-02-09 13:24

    If you have already the bits in the form of a string, use strrev.

    If not, convert first the byte to its binary representation by using decbin, then reverse using strrev, then go back to byte (if necessary) by using bindec.

提交回复
热议问题