如何获得 SHORT 的高位和低位? [英] How do I get the high- and low-order bits of a SHORT?

查看:35
本文介绍了如何获得 SHORT 的高位和低位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

函数 GetKeyState() 返回一个包含键状态的 SHORT(高位向上/向下,低位切换).我如何获得这些值?

The function GetKeyState() returns a SHORT that contains the key's state (up/down in the high-order bit, and toggled in the low-order). How do I get those values?

推荐答案

简单的位操作即可.SHORT 是 16 位整数,因此要获取低位和高位,您可以执行以下操作:

Simple bit manipulation will work. SHORTs are 16-bit integers, so to get the low- and high-order bits you can do the following:

lowBit = value & 1;
highBit = ((unsigned short) value) >> 15;

另外,请注意 LOBYTE 和 HIBYTE 宏用于将 SHORT 分成低位和高位字节,而不是测试字节中的单个位.

Also, note that the LOBYTE and HIBYTE macros are used to break SHORTs into low- and high-order bytes, not to test individual bits in a byte.

这篇关于如何获得 SHORT 的高位和低位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆