简单类型 / 数字 / Integer

let a = 5 //0101
let b = 6 //0110

//And
let c1 = a & b
//c1 is 4 (0100)

//Or
let c2 = a | b
//c2 is 7 (0111)

//Xor
let c3 = a ^ b
//c3 is 3 (0011)

//shift right
let c4 = a >> 1
//c4 is 2 (0010)

//shift left
let c5 = b << 1
//c5 is 12 (1100)

//bits inversion
let c6 = ~b
//c6 is -7 (-111)

print("c1 = \(c1)")
print("c2 = \(c2)")
print("c3 = \(c3)")
print("c4 = \(c4)")
print("c5 = \(c5)")
print("c6 = \(c6)"