Search code examples
pythonopencvhex

What's 0xFF for in cv2.waitKey(1)?


I'm trying understand what 0xFF does under the hood in the following code snippet:

if cv2.waitKey(0) & 0xFF == ord('q'):
    break

Any ideas?


Solution

  • 0xFF is a hexadecimal constant which is 11111111 in binary. By using bitwise AND (&) with this constant, it leaves only the last 8 bits of the original (in this case, whatever cv2.waitKey(0) is).