简体   繁体   English

为什么在检查大写锁定时需要&0xFFFF

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

I'm trying to check if CAPS LOCK is on. 我正在尝试检查CAPS LOCK是否打开。 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. 我已经看过以下几行,我想知道为什么需要使用0xFFFF的AND,因为使用0xFFFF的AND将返回完全相同的数字。 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? 我在这里已经读到,为了检查CAPS LOCK是否已切换,您需要检查低位,因此它应该与1相加。那么,为什么选择0xFFFF?

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

Thanks! 谢谢!

I aggree with GSerg that it is not needed to be used. 我同意GSerg,不需要使用它。 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. 您可以使用此在线按位计算器来了解其工作原理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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