Bitwise NOT
You use the bitwise NOT operator when you want to invert all the bits. You write the bitwise NOT as a tilde (~). If you invert 0b00001111, you get 0b11110000, which is 240. You can try this out in playground. You represent the 8 bits as 1 byte by using UInt8. The 8 in UInt8 stands for the number of bits. UInt8 represents 1 byte because it has 8 bits available to store things. This means you have values from 1 to 255 available to you with UInt8. This is the case because if you make all 8 bits set to 1, then 0b11111111 is equal to 255. If you use UInt16, then you have 16 bits available to you, and your max value is much larger, at 65,535. You can try this out in the calculator as we mentioned in the previous section.
Let’s get back ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access