From 1ab9831597a7104b4303b959f9a791cca3f1bde6 Mon Sep 17 00:00:00 2001 From: flykhan Date: Mon, 19 Jun 2023 15:41:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=8D=E8=BF=90=E7=AE=97=E5=B7=A6=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day6/d8.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 day6/d8.cpp 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