Bitwise operations with Int in Swift
Forums:
let a = 5 //0101
let b = 6 //0110
//And
var 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