diff --git a/day6/d8.cpp b/day6/d8.cpp new file mode 100644 index 0000000..28a7d8a --- /dev/null +++ b/day6/d8.cpp @@ -0,0 +1,20 @@ +/* + 0b 1100 0011 << 2 -67 + 0b 0000 1100 12 + + 将二进制数向左(高位)移动,低位补0. + [注意]左移是包含符号位的. +*/ +#include +#include + +using namespace std; + +int main() +{ + char n = 0b11000011; // 0b 表示二进制表示法 0b11000011 = 195 + cout << "n = " << bitset<8>(n) << endl; // n = 11000011 + n = n << 2; // 建议不要使用 <<= 运算符,因为它会改变 n 的类型 // 0b00001100 = 12 195 << 2 = 12 + cout << "n = " << bitset<8>(n) << "\t" << (int)n << endl; // n = 00001100 + return 0; +} \ No newline at end of file