Tutorial by Examples

int a = 6; // 0110b (0x06) int b = 10; // 1010b (0x0A) int c = a & b; // 0010b (0x02) std::cout << "a = " << a << ", b = " << b << ", c = " << c << std::endl; Output a = 6, b = 10, c = 2 Why A bit wise A...
int a = 5; // 0101b (0x05) int b = 12; // 1100b (0x0C) int c = a | b; // 1101b (0x0D) std::cout << "a = " << a << ", b = " << b << ", c = " << c << std::endl; Output a = 5, b = 12, c = 13 Why A bit wise OR o...
int a = 5; // 0101b (0x05) int b = 9; // 1001b (0x09) int c = a ^ b; // 1100b (0x0C) std::cout << "a = " << a << ", b = " << b << ", c = " << c << std::endl; Output a = 5, b = 9, c = 12 Why A bit wise XOR (...
unsigned char a = 234; // 1110 1010b (0xEA) unsigned char b = ~a; // 0001 0101b (0x15) std::cout << "a = " << static_cast<int>(a) << ", b = " << static_cast<int>(b) << std::endl; Output a = 234, b = 21 Why A b...
int a = 1; // 0001b int b = a << 1; // 0010b std::cout << "a = " << a << ", b = " << b << std::endl; Output a = 1, b = 2 Why The left bit wise shift will shift the bits of the left hand value (a) the number specified on the right...
int a = 2; // 0010b int b = a >> 1; // 0001b std::cout << "a = " << a << ", b = " << b << std::endl; Output a = 2, b = 1 Why The right bit wise shift will shift the bits of the left hand value (a) the number specified on the righ...

Page 1 of 1