标签:blog ar sp div on log ad bs as
//____逻辑移动是针对无符号数的______________________________________________
逻辑左移 SHL 逻辑右移 SHR: unsigned int i = 0x1234; unsigned int j = 0; j = i >> 8; //右移, 执行后 j = 0x12; j = i << 8; //左移, 执行后 j = 0x123400;
//_____算术移动是针对有符号数的_____________________________________________ 算术左移 SAL 算术右移 SAR: int i = 0x88332211; int j = 0; j = i << 8; //左移, 执行后 j = 0x33221100; 与逻辑左移相同. j = i >> 8; //右移, 执行后 j = FF883322; 移进来的位, 全置1.
注意: ROR, ROL会把符号位也移动起来, 即把有符号数当成无符号数处理. 这很可怕, 会改变有符号数的正负号, 呵呵.//_____异同_______________________________________________________________ 相同之处: SHL = SAL; 当有符号数为正数时 SAR = SHR高位用0填补. 不同之处: 当有符号数为负数时, SAR 高位用1填补. //_____循环位移___________________________________________________________ 循环位移只有汇编指令, C语言中没有相应描述. 所以只能用汇编指令编写程序 int i = 0x77665544; __asm { ROR i, 8 //执行后, i = 0x44776655; } |
标签:blog ar sp div on log ad bs as
原文地址:http://www.cnblogs.com/goalpower/p/4032590.html