Everyone is familiar with decimal numbers. However, computers use binary and hexadecimal representations of numbers. We also need to learn how to deal with bits, and bitwise operators.
Do you know the answers to the following questions?
- What is the decimal value of
- What is
- What is
- What is the minimum number of bits required to store the number 8?
- What does
- The six bitwise operators are
>>(left and right shift). Do you know how each operates? What is the result of evaluating the following expressions:
0x01 & 0x02
0x01 | 0x2
0x01 ^ 0x02
0x01 << 2
- Given a number
x, what expression computes a new number
ythat is equal to
xbut with a zero in its least significant bit?
Try your hand at these exercises on base conversion and bitwise operations used for practice in the first lab of the regular CS107.
If you don't know the answers to these questions, we recommend that you review the following materials:
- Khan Academy video on Number Systems
- Wikipedia entry for Binary Numbers
- Sparkfun tutorial on Hexadecimal Numbers
- Wikipedia entry for Bitwise Operators
- Play with the Bitwise Explorer, an visualizer for bitwise expressions written by CS107 TA Max Drach
Credit to: http://cowbirdsinlove.com/43