CPS 4.01 - Spring, 2002 - Ramm 1/30/02
Binary Arithmetic
- Work with only 2 Digit Values: 0 and 1
- Two values, thus: binary
- Binary digit usually called bit
- Addition: Use Same Kinds of Rules a Decimal
- Carry when sum is too large
- Start with 0
- Start adding 1's to get numbers
- Is like Counting:
- Can get Binary Number table:
| System: | Binary | | | Dec
|
|---|
| Weights: | 8 | 4 | 2 | 1 | | | 10 | 1
|
|---|
| 0 | 0 | 0 | 0 | | | 0 | 0
|
| 0 | 0 | 0 | 1 | | | 0 | 1
|
| 0 | 0 | 1 | 0 | | | 0 | 2
|
| 0 | 0 | 1 | 1 | | | 0 | 3
|
| 0 | 1 | 0 | 0 | | | 0 | 4
|
| 0 | 1 | 0 | 1 | | | 0 | 5
|
| 0 | 1 | 1 | 0 | | | 0 | 6
|
| 0 | 1 | 1 | 1 | | | 0 | 7
|
| 1 | 0 | 0 | 0 | | | 0 | 8
|
| 1 | 0 | 0 | 1 | | | 0 | 9
|
| 1 | 0 | 1 | 0 | | | 1 | 0
|
| 1 | 0 | 1 | 1 | | | 1 | 1
|
| 1 | 1 | 0 | 0 | | | 1 | 2
|
| 1 | 1 | 0 | 1 | | | 1 | 3
|
| 1 | 1 | 1 | 0 | | | 1 | 4
|
| 1 | 1 | 1 | 1 | | | 1 | 5
|
- Conversion to and from Decimal
- To convert to decimal, use weights (as shown in table)
- To convert to binary, use the successive division method (in text)
- Multiplication and Division by 2
- Think of what happens in decimal when multiplying (or dividing) by 10
- Equivalent of binary shift operations
- How Large a Number Can it Hold?
- One bit can hold 2 different values
- Two bits can hold 4 different values
- Three bits can hold ...
- Do We Need Negative Numbers?
- Most languages allow signed and unsigned integers
- Signed Integers
- Sign Magnitude System (used in quiz)
- Easy for beginners
- Hard on computers
- Two's Complement System
- Less intuitive for people
- Easy on computers