0

I have seen in THIS openCV example that they use

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

to check if the user pressed the character 'q'

Why are they doing the & 0xFF part?

If you have a bit x and you do x AND 1 the bit remains the same. So doing an AND to all ones (0xFF) would keep the result the same.

Why is it done then?

  • 1
    http://stackoverflow.com/q/35372700/2836621 – Mark Setchell Feb 24 '16 at 17:18
  • 2
    if you can imagine 0xff as 0x00ff, you'll see, that it masks out the lower 8bit (ascii) nibble from a possible 16bit scankey value. (you get the latter on some os/gui combination) – berak Feb 24 '16 at 17:18
  • Makes sense now. Thanks. –  Feb 25 '16 at 09:04
  • Possible duplicate of [What's 0xFF for in cv2.waitKey(1)?](https://stackoverflow.com/questions/35372700/whats-0xff-for-in-cv2-waitkey1) – Jason Aug 14 '18 at 14:11

0 Answers0