How to do it...

The operators we will explore are known as bitwise operators, and are used to manipulate numerical bit representations, so let's get started.

An integer value in Swift can be represented in its binary form by prefixing the integer literal with 0b:

let zero: Int  = 0b000 let one: Int   = 0b001 let two: Int   = 0b010 let three: Int = 0b011 let four: Int  = 0b100 let five: Int  = 0b101 let six: Int   = 0b110 let seven: Int = 0b111 

A bit is the smallest value in a computer system, consisting of either a 1 or 0. The integers mentioned here can be represented by three bits, which are clearly visible when it's represented in binary form, as illustrated in the preceding snippet. The integer 6 can be represented by the three bits 1, 1, and ...

Get Swift 4 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.