Bitwise operations with int in C#
Forums:
int a = 5; //0101
int b = 6; //0110
//And
int c = a & b;
//c is 4 (0100)
//Or
c = a | b;
//c is 7 (0111)
//Xor
c = a ^ b;
//c is 3 (0011)
//shift right
c = a >> 1;
//c is 2 (0010)
//shift left
c = b << 1;
//c is 12 (1100)
- Log in to post comments