以底下兩數字為例:
let bin1:UInt8 = 0b11111111 //255
let bin2:UInt8 = 0b00001000 //8
and運算
let andResult = bin1 & bin2
print(String(andResult,radix: 2))//00001000
or運算
let orResult = bin1 | bin2
print(String(orResult,radix: 2))//11111111
xor運算
let xorResult = bin1 ^ bin2
print(String(xorResult,radix: 2))//11110111
not運算
let notBin1Result = ~bin1
print(String(notBin1Result,radix: 2))//00000000
let notBin2Result = ~bin2
print(String(notBin2Result,radix: 2))//11110111
nor運算
let norResult = ~(bin1 | bin2)
print(String(norResult,radix: 2))//00000000