CSC-105
Introduction to Computer Science
Lecture 2.2.
Alternative Number Systems
Octal Number System
your new hands
Decimal vs. Octal System
| Decimal system | Octal System |
Number of dwarfs in Snow White | 7 | 7 |
Fingers that cartoon characters have | 8 | 10 |
Symphonies of Beethoven | 9 | 11 |
Fingers that human have | 10 | 12 |
Number of months in a year | 12 | 14 |
Number of letters in the Latin alphabet | 26 | 32 |
Decimal vs. Octal System
= 32 (in octal)
= 3 * 8 + 2 (in decimal)
= 26 (in decimal)
Octal vs. Decimal System
Decimal System
Each position in an octal number is a digit that’s multiplied by a power of eight
Octal System
Converting Octal to Decimal
3725 = 3000 + 700 + 20 + 5
3725 = 3 x 100 +
7 x 100 +
2 x 10 +
5 x 1
3725 = 3 x 83 +
7 x 82 +
2 x 81 +
5 x 80
(Octal)
(Decimal)
(Octal)
Addition in Octal Number System
Addition in Octal Number System
1 3 5 8 |
|
|
Multiplication in Octal Number System
Number System for lobsters
0, 1, 2, 3, 10, 11, 12, 13, 20, 21, 22, ..... and so forth
Number System in Base Four
In base 4, the number 31232 can be written like this:
31232 = 3 x 10000 +
1 x 1000 +
2 x 100 +
3 x 10 +
2 x 1
31232 = 3 x 44 +
1 x 43 +
2 x 42 +
3 x 41 +
2 x 40
Number System for Dolphins
0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001...
Decimal vs. Binary
| Decimal system | Binary System |
Number of heads that humans have | 1 | 1 |
Number of flippers on a dolphin | 2 | 10 |
Number of teaspoons in a tablespoon | 3 | 11 |
Number of sides to a square | 4 | 100 |
Number of fingers on one human hand | 5 | 101 |
Number of legs on an insect | 6 | 110 |
Number of days in a week | 7 | 111 |
Binary System
Binary System
Converting from Binary to Decimal
101101011010 = | 1 x 100000000000 + |
| 0 x 10000000000 + |
| 1 x 1000000000 + |
| 1 x 100000000 + |
| 0 x 10000000 + |
| 1 x 1000000 + |
| 0 x 100000 + |
| 1 x 10000 + |
| 1 x 1000 + |
| 0 x 100 + |
| 1 x 10 + |
| 0 x 1 |
101101011010 = | 1 x 211 + |
| 0 x 210 + |
| 1 x 29 + |
| 1 x 28 + |
| 0 x 27 + |
| 1 x 26 + |
| 0 x 25 + |
| 1 x 24 + |
| 1 x 23 + |
| 0 x 22 + |
| 1 x 21 + |
| 0 x 20 = 2906 |
Converting from Base b to Decimal
dndn-1.... d1d0 = | dn x basen + |
| dn-1 x basen-1 + |
| dn-2 x basen-2 + |
| . |
| . |
| . |
| . |
| . |
| . |
| . |
| d1 x b1 + |
| d0 x b0 = Output |
Input: An n-digit number in base b dndn-1....d1d0
where di represents the digit in ith place
and the first place (right most) is 0
Algorithm:
Converting from Decimal to Binary
Input: 290610
Algorithm:
2 | 2906 | |
2 | 1453 | 0 |
2 | 726 | 1 |
2 | 363 | 0 |
2 | 181 | 1 |
2 | 90 | 1 |
2 | 45 | 0 |
2 | 22 | 1 |
2 | 11 | 0 |
2 | 5 | 1 |
2 | 2 | 1 |
| 1 | 0 |
Converting from Decimal to Binary
2 | 2906 | |
2 | 1453 | 0 |
2 | 726 | 1 |
2 | 363 | 0 |
2 | 181 | 1 |
2 | 90 | 1 |
2 | 45 | 0 |
2 | 22 | 1 |
2 | 11 | 0 |
2 | 5 | 1 |
2 | 2 | 1 |
| 1 | 0 |
Input: 290610
Algorithm:
Output: 1011010110102
Converting from Decimal to Base b
b | Input | |
b | Quotient 1 | Remainder 1 |
b | Quotient 2 | Remainder 2 |
. | . | . |
. | . | . |
. | . | . |
. | . | . |
. | . | . |
b | Quotient n-3 | Remainder n-3 |
b | Quotient n-2 | Remainder n-2 |
b | Quotient n-1 | Remainder n-1 |
| Quotient n | Remainder n |
Input: Input
Algorithm:
Output:
Quotientn Remaindern Remaindern-1 .... Remainder1
Converting from Decimal to Binary
Converting from Decimal to Binary
Adding Binary Numbers
1 1 0 2 |
|
|
Subtracting Binary Numbers
1 1 0 2 |
- 1 1 1 2 |
|