For the purposes of this exercise we will be working with the binary representation of two numbers. Firstly, the decimal number 171 is represented in binary as:
For the purposes of this exercise we will be working with the binary representation of two numbers. Firstly, the decimal number 171 is represented in binary as:
−
10101011
+
<tt>10101011</tt>
Secondly, the number 3 is represented by the following binary sequence:
Secondly, the number 3 is represented by the following binary sequence:
−
00000011
+
<tt>00000011</tt>
Now that we have two binary numbers with which to work, we can begin to look at the Swift bitwise operators:
Now that we have two binary numbers with which to work, we can begin to look at the Swift bitwise operators:
The Bitwise NOT is represented by the tilde character and has the effect of inverting all of the bits in a number. In other words, all the zeros become ones and all the ones become zeros. Taking our example 3 number, a Bitwise NOT operation has the following result:
The Bitwise NOT is represented by the tilde character and has the effect of inverting all of the bits in a number. In other words, all the zeros become ones and all the ones become zeros. Taking our example 3 number, a Bitwise NOT operation has the following result: