c++按位取数的问题,求助高手我要从数据库去出一个数据是32位的,它包含了两个信息,一个是UShort nLac 和US
c++按位取数的问题,求助高手
我要从数据库去出一个数据是32位的,它包含了两个信息,一个是UShort nLac; 和UShort nCi;,nlac的信息在高16位,nCi的信息在低16位,请问我应该怎么把这个32位的数据取出给到nLac 和 nCi中呢?求高手相助,在线等。谢谢。
[解决办法]
nLac = (UShort)(x >> 16);
nCi = (UShort)x;
[解决办法]
long a = 0xABCD;
nLac = (UShort)(a >> 16);
nCi = (UShort)(a & 0x00FF);
[解决办法]
- C/C++ code
#include <iostream>using namespace std;int main(int argc, char** argv){ int a = 0xabcd1234; unsigned short highpart = (unsigned short) (a >> 16); unsigned short lowpart = (unsigned short) a; cout << "highpart = " << highpart << endl; // 输出43981 = 0xabcd cout << "lowpart = " << lowpart << endl; // 输出4660 = 0x1234 return 0;} 