#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<8> bit_1;
bit_1.reset();
bit_1 = 127; // 0111 1111
bitset<8> bit_2;
bit_2.reset();
bit_2 = 0x20; //32, 0100 0000
bitset<8> bit_3 = bit_1 & bit_2;
bitset<8> bit_4 = bit_1 | bit_2;
bitset<8> bit_5 = bit_1 ^ bit_2;
bitset<8> bit_6 = ~bit_1;
bitset<8> bit_7 = bit_2 << 1;
bitset<8> bit_8 = bit_2 >> 1;
cout << bit_3 << ", " << bit_3.to_ulong() << endl;
cout << bit_4 << ", " << bit_4.to_ulong() << endl;
cout << bit_5 << ", " << bit_5.to_ulong() << endl;
cout << bit_6 << ", " << bit_6.to_ulong() << endl;
cout << bit_7 << ", " << bit_7.to_ulong() << endl;
cout << bit_8 << ", " << bit_8.to_ulong() << endl;
return 0;
}
00100000, 32
01111111, 127
01011111, 95
10000000, 128
01000000, 64
00010000, 16
https://learn.microsoft.com/ko-kr/cpp/standard-library/bitset-class?view=msvc-170
bitset 클래스
자세한 정보: bitset 클래스
learn.microsoft.com
#include <bitset>를 이용
bitset<개수> 이름;:: bitset 선언
bit.reset() :: 전체 비트를 0으로 리셋
https://ko.wikihow.com/16%EC%A7%84%EC%88%98%EB%A5%BC-2%EC%A7%84%EC%88%98%EC%99%80-10%EC%A7%84%EC%88%98%EB%A1%9C-%EB%B3%80%ED%99%98%ED%95%98%EB%8A%94-%EB%B2%95
16진수를 2진수와 10진수로 변환하는 법: 6 단계 (이미지 포함) - wikiHow
가끔 보이는 이상한 알파벳과 숫자가 섞인 문자를 당신이나 컴퓨터가 이해할 수 있게 바꾸려면 어떻게 해야 할까? 일단 16진수를 2진수로 바꾸는 것은 매우 쉽다. 그래서 일부 프로그래밍 언어에
ko.wikihow.com
and 연산 : 두값이 모두 1일때 1
or 연산 : 두 값이 하나만 1이어도 1
xor 연산 : 두 값이 0으로 같아도 0, 1으로 같아도 0, 값이 서로 다를때 1
~ 연산 : 비트를 반전