December 2014
Beginner
300 pages
8h 9m
English
Bitwise OR is written using a single pipe: |. Whereas bitwise AND returns the new number if both bits are set to 1, bitwise OR returns the new number if either bit is equal to 1 (see Figure 7.5).
Figure 7.5 Performing a bitwise OR on two bytes with the result in the middle.
When you use the bitwise OR operator, the result is all 1s (255). You can try this out with code like so:
var a:UInt8 = 0b11111010 //250var b:UInt8 = 0b01010111 //87a|b //255
Figure 7.6 shows another example where both inputs are 0, so the resulting bit is 0 also.
Figure 7.6 Another bitwise OR comparing two bytes.
You could write ...
Read now
Unlock full access