Work with integers as binary in C++

int x = 0b00100;
int y = 0b00101;
int z = a + b;
cout << z << endl;
9
#include <bitset>
cout << std::bitset<6>(z) << endl;
#include <cstddef>
byte myByte{ 2 };
myByte <<= 2;
cout << to_integer<int>(myByte) << endl;
byte byte1{ 0b0011 };byte byte2{ 0b1010 };
byte byteOr = byte1 | byte2;
byte byteAnd = byte1 & byte2;
cout << to_integer<int>(byteOr) << endl;

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store