对一个无符号字符变量左移8位表示啥?
请大牛解答,对一个无符号字符变量左移8位表示啥啊?然后再与另一个无符号字符变量逻辑或。迷惑不解
unsigned char uc1;
uc1 << 8;//表示啥
unsigned char uc2;
(uc1 << 8) | uc2;//再与uc2逻辑或,表示啥
[解决办法]
仅供参考
//The _getch function reads a single character from the console without echoing.//Function can not be used to read CTRL+Break.//When reading a function key or an arrow key,//_getch must be called twice; the first call returns 0 or 0xE0,//and the second call returns the actual key code.#include <conio.h>#include <windows.h>void main() { unsigned short k; while (1) { Sleep(100); k=getch(); if (27==k) break;//按Esc键退出 if (0==k||0xe0==k) k|=getch()<<8;//非字符键 cprintf("%04x pressed.\r\n",k); }}
[解决办法]
uc1<<8在寄存器中会显示低8位为0,原来的uc1的值移到了第7--16位。
与uc2或后,寄存器应该是7--16位是uc1,低8位是uc2.然后就看你这个寄存器内的值赋值给谁了。
[解决办法]
就是Uc2吧