A.6: Bit Manipulation
- 2.Bit manipulation refers to manipulation of the bits that form a value using bitwise operators
- 3.Know the 6 most common bitwise operators (
>>) and what they do
Bit manipulation refers to changing bits in a value using bitwise operators. In the algorithm interview context, this typically involves manipulating bits that represent numbers.
There are 6 most common bitwise operators:
>>. Let us examine them in a table.
Before trying bitwise operators on your own in a Node console, read the following article with diagrams on how each operator works, and watch the following illustrative videos.
Introduction to basic bitwise operators and how they can be used in practice
Deeper introduction to binary numbers and how to manipulate those numbers using bitwise operators
Example of how to add 2 numbers using only bitwise operators
toString(2)method on numbers to convert integers (aka decimal numbers) to binary numbers, and
toString(10)to convert binary numbers to integers. For Python, consider using the equivalent built-in functions