qfedu-basic-level/day6/d9.cpp

28 lines
1.5 KiB
C++
Raw Normal View History

2023-06-19 15:54:34 +08:00
/*
(), ,,0,.,.
*/
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
char n = 0xff; // 0b1111 1111
/*
.,0,,,.,,0,,1.
.,0,.,1,.,,.
*/
n = n >> 4; // 逻辑右移: 0b0000 1111 ; 算术右移: 0b1111 1111
// 如何判断高 4 位是 1111 还是 0000
// 1. 逻辑右移, 0b0000 1111
// 2. 算术右移, 0b1111 1111
if (n & 0xff == 0x0f)
cout << "0xff >> 4 进行逻辑右移, 结果: " << bitset<8>(n) << endl;
else
cout << "0xff >> 4 进行算术右移, 结果: " << bitset<8>(n) << endl;
return 0;
}