Bootcamp

Searchโฆ

A.12: Bit Manipulation

Bit manipulation is commonly taught in core computer science courses to help students understand how numbers are represented and manipulated by computers. Some companies use bit manipulation in their interview processes.

Please read about the 6 main bitwise operators

`&`

, `|`

, `~`

, `^`

, `<<`

, and `>>`

here. These operators can be used in Python to perform bitwise operations.A Hamming Code is an error-correction algorithm that uses bit manipulation to check if a set of data has errors (specifically binary data) in O(logn) space and time. These videos give a good intuition of the usefulness of bit manipulation as it relates to binary data.

Hamming codes have a Hamming distance of 3: The algorithm can detect up to three errors per block.

- 1.
- 1.Hint: If
`A XOR B == C`

, then`C XOR A == B`

and`C XOR B == A`

. - 2.
- 3.

- 4.
- 1.Consider using Python's built-in decimal to binary converter function
`bin()`

- 1.
- 1.Requires trick to understand what happens when we XOR a number with 0, and when we XOR a number with itself

Two's complement

Last modified 5mo ago

Copy link

On this page

Introduction

Use Case: Hamming Codes

Exercises

Pre-Class

Part 1

More Comfortable

Further Reading