简体   繁体   中英

Why is & 0xFFFF needed when checking if caps lock on

I'm trying to check if CAPS LOCK is on. I have seen the following line and I was wondering why is the AND with 0xFFFF needed since AND with 0xFFFF will return exactly the same number. I have read here that in order to check if the CAPS LOCK is toggled, you need to check the lower-order bit hence it should be AND with 1. So, why 0xFFFF?

bool CapsLock = (((ushort)GetKeyState(0x14)) & 0xffff) != 0;

Thanks!

I aggree with GSerg that it is not needed to be used. But normally the use of and bitwise operator is to get portion of the value.

for instance:

0x11ffff
0xffff 
--------- AND
0xffff

You can use this online bitwise calculator to understand how it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM