rolror.cpp
来自「Thinking_in_C___2.rar」· C++ 代码 · 共 29 行
CPP
29 行
//: C03:Rolror.cpp {O}
// From Thinking in C++, 2nd Edition
// at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
// Perform left and right rotations
unsigned char ROL(unsigned char val) {
int highbit;
if(val & 0x80) // 0x80 is the high bit only
highbit = 1;
else
highbit = 0;
val <<= 1; // Left shift (bottom bit becomes 0)
val |= highbit; // Rotate the high bit onto the bottom
return val; // This becomes the function value
}
unsigned char ROR(unsigned char val) {
int lowbit;
if(val & 1) // Check the low bit
lowbit = 1;
else
lowbit = 0;
val >>= 1; // Right shift by one position
val |= (lowbit << 7); // Rotate the low bit onto the top
return val;
} ///:~
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?