Chapter 2

advertisement
Course-Related Matters
■ The drop-boxes for EECS 1520 will be
moved by the end of this week to the west
side of 1012F Lassonde building.
■ Homework 1
–
–
–
–
Due next week (Jan. 27, 2015) firm
Data view v.s. Formula view
Tips on printing
For Q1, as it states in the homework description:
“You can make up any numbers you like for the
‘raw data’ …”
EECS 1520
Computer Use: Fundamentals
Week 3:
(Textbook) Chapter 2 - Binary Numbers
and Number Systems
Zhen Ming (Jack) Jiang
Number Categories
■ Number
– Unit of a mathematical system subject to arithmetic
■ Natural numbers
– 0, 1, 2, 3, 4…
■ Negative numbers
– Number less then 0, i.e. -1, -2, -3, -4…
■ Integers
– …-4, -3, -2, -1, 0, 1, 2, 3, 4…
■ Rational numbers
– Fraction of integers (except division by 0)
– E.g., ¼, ½, -7/13…
The Idea of a Positional Number
System
4357 four thousand, three hundred and fifty seven
four units of a thousand (4 x 1000)
three units of a hundred (3 x 100)
five units of ten (5 x 10)
seven units of one (7 x 1)
4000
300
50
7
4 x 103 + 3 x 102 + 5 x 101 + 7 x 100
5743 same digits, different positions, different number
The position of each digit determines that digit’s contribution to
the number.
The Idea of
a Positional Number System
base: b any integer > 1
digits: 0, 1, ..., b−1
number: dn-1dn-2…d2d1d0
its definition:
dn-1 x bn-1 + dn-2 x bn-2 + … + d2 x b2 + d1 x b1 + d0 x b0
Examples:
Base
Digits
2
5
8
10
16
0,
0,
0,
0,
0,
1
1,
1,
1,
1,
2,
2,
2,
2,
3,
3,
3,
3,
4
4, 5, 6, 7
4, 5, 6, 7, 8, 9
4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Binary, Octal and Hexadecimal
Comparison of first natural numbers in four different bases
etc...
Arithmetic in Other Bases
All the familiar rules of pencil-and-paper decimal arithmetic carry over to any
other base
Decimal Grid
Addition
46
+ 27
101110
+ 11011
Subtraction
5037
- 95
57
- 6
111001
110
Binary Grid
Octal Grid
Hexadecimal Grid
Examples of Arithmetic
In Octal:
3754
+6317
76312
+ 4634
3B6F
+5743
89FCD
+ 9FD
In Hexadecimal:
In Decimal:
123
+ 45
+3682
+ 12
+ 654
Conversion between
Decimal and Binary
■ Binary to Decimal
– Use the definition of a number in a positional number
system with base 2
– Evaluate the definition formula using decimal arithmetic
■ Example
101011 = 1 x 25 + 0 x 24 + 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20
= 43 (decimal)
Conversion between
Decimal and Binary
■ Decimal to Binary
–
–
–
–
Repeatedly divide by 2
Quotient Carries
Remainder is the next digit
Binary number is developed right to left
■ Example
173
86
43
21
10
5
2
1
(Quotient)
÷
÷
÷
÷
÷
÷
÷
÷
2
2
2
2
2
2
2
2
86
43
21
10
5
2
1
0
(Remainder)
1
0
1
1
0
1
0
1
(Binary)
1
01
101
1101
01101
101101
0101101
10101101
Generalization: Conversion
between Decimal and Base b
■ Base b to Decimal
– Use the definition of a number in a positional
number system with base b
– Evaluate the definition formula using decimal
arithmetic
■ Decimal to base b
– Repeatedly divide by b
– Quotient carries
– Remainder is the next digit
– Base b number is developed right to left
Conversion between Binary and
Octal/Hexadecimal
■ Binary to Octal
– Group bits into threes, right to left
– Convert each group into an octal digit
■ Example
1011010111 = 001 011 010 111 = 1327 (octal)
■ Binary to Hexadecimal
– Group bits into fours, right to left
– Convert each group into a hexadecimal digit
■ Example
1011001011 = 0010 1100 1011 = 2CB
(hexadecimal)
Conversion between Binary and
Octal/Hexadecimal
■ Octal to Binary
– Convert each digit to a three-bit binary representation
■ Example
705 = 111 000 101 = 111000101 (binary)
■ Hexadecimal to Binary
– Convert each digit to a four-bit binary representation
■ Example
10AF = 0001 0000 1010 1111
= 0001000010101111 (binary)
Conversion tables can be reconstructed in the margins of
a test paper when needed
What about converting between
Octal and Hexadecimal?
■ Hexadecimal is not base 8, so grouping won’t
work as in binary  octal or binary 
hexadecimal
■ Octal to Hexadecimal
– Convert octal to binary and then binary to
hexadecimal
■ Hexadecimal to Octal
– Convert hexadecimal to binary and then to octal
Download