Bài giảng Kiến trúc máy tính - Chương 3, Phần 1: Data representation - Võ Tấn Phương

dce  
2015  
COMPUTER ARCHITECTURE  
CSE Fall 2014  
Faculty of Computer Science and Engineering  
Department of Computer Engineering  
BK  
TP.HCM  
Vo Tan Phuong  
dce  
2015  
Chapter 3  
Data Representation  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
2
dce  
2015  
Presentation Outline  
• Positional Number Systems  
• Binary and Hexadecimal Numbers  
• Base Conversions  
• Binary and Hexadecimal Addition  
• Binary and Hexadecimal subtraction  
• Carry and Overflow  
• Character Storage  
• Floating Point Number  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
3
dce  
2015  
Positional Number Systems  
Different Representations of Natural Numbers  
XXVII Roman numerals (not positional)  
27 Radix-10 or decimal number (positional)  
110112 Radix-2 or binary number (also positional)  
Fixed-radix positional representation with k digits  
Number N in radix r = (dk–1dk–2 . . . d1d0)r  
Value = dk–1×r k–1 + dk–2×r k–2 + … + d1×r + d0  
Examples: (11011)2 = 1×24 + 1×23 + 0×22 + 1×2 + 1 = 27  
(2103)4 = 2×43 + 1×42 + 0×4 + 3 = 147  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
4
dce  
2015  
Binary Numbers  
• Each binary digit (called bit) is either 1 or 0  
• Bits have no inherent meaning, can represent  
– Unsigned and signed integers  
– Characters  
Most  
Significant Bit  
Least  
Significant Bit  
– Floating-point numbers  
– Images, sound, etc.  
7
6
5
4
3
2
1
0
1 0 0 1 1 1 0 1  
• Bit Numbering  
27 26 25 24 23 22 21 20  
– Least significant bit (LSB) is rightmost (bit 0)  
– Most significant bit (MSB) is leftmost (bit 7 in an 8-bit number)  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
5
dce  
2015  
Converting Binary to Decimal  
• Each bit represents a power of 2  
• Every binary number is a sum of powers of 2  
• Decimal Value = (dn-1 2n-1) + ... + (d1 21) + (d0 20)  
• Binary (10011101)2 = 27 + 24 + 23 + 22 + 1 = 157  
7
6
5
4
3
2
1
0
1 0 0 1 1 1 0 1  
27 26 25 24 23 22 21 20  
Some common  
powers of 2  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
6
dce  
2015  
Convert Unsigned Decimal to Binary  
• Repeatedly divide the decimal integer by 2  
• Each remainder is a binary digit in the translated value  
least significant bit  
37 = (100101)2  
most significant bit  
stop when quotient is zero  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
7
dce  
2015  
Hexadecimal Integers  
• 16 Hexadecimal Digits: 0 – 9, A – F  
• More convenient to use than binary numbers  
Binary, Decimal, and Hexadecimal Equivalents  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
8
dce  
2015  
Converting Binary to Hexadecimal  
Each hexadecimal digit corresponds to 4 binary bits  
Example:  
Convert the 32-bit binary number to hexadecimal  
1110 1011 0001 0110 1010 0111 1001 0100  
Solution:  
E
B
1
6
A
7
9
4
1110 1011 0001 0110 1010 0111 1001 0100  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
9
dce  
2015  
Converting Hexadecimal to Decimal  
• Multiply each digit by its corresponding power of 16  
Value = (dn-1 16n-1) + (dn-2 16n-2) + ... + (d1 16) + d0  
• Examples:  
(1234)16 = (1 163) + (2 162) + (3 16) + 4 =  
Decimal Value 4660  
(3BA4)16 = (3 163) + (11 162) + (10 16) + 4 =  
Decimal Value 15268  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
10  
dce  
2015  
Converting Decimal to Hexadecimal  
Repeatedly divide the decimal integer by 16  
Each remainder is a hex digit in the translated value  
least significant digit  
most significant digit  
stop when  
quotient is zero  
Decimal 422 = 1A6 hexadecimal  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
11  
dce  
2015  
Integer Storage Sizes  
8
Byte  
Half Word  
Word  
Storage Sizes  
16  
32  
Double Word  
64  
Storage Type  
Unsigned Range  
0 to 255  
Powers of 2  
Byte  
0 to (28 – 1)  
0 to (216 – 1)  
0 to (232 – 1)  
0 to (264 – 1)  
Half Word  
Word  
0 to 65,535  
0 to 4,294,967,295  
Double Word  
0 to 18,446,744,073,709,551,615  
What is the largest 20-bit unsigned integer?  
Answer: 220 – 1 = 1,048,575  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
12  
dce  
2015  
Binary Addition  
• Start with the least significant bit (rightmost bit)  
• Add each pair of bits  
• Include the carry in the addition, if present  
carry  
1
1
1
1
0 0 1 1 0 1 1 0  
0 0 0 1 1 1 0 1  
(54)  
(29)  
+
0 1 0 1 0 0 1 1  
(83)  
bit position: 7  
6
5
4
3
2
1
0
Computer Architecture – Chapter 3  
© Spring 2015, CE  
13  
dce  
2015  
Hexadecimal Addition  
• Start with the least significant hexadecimal digits  
• Let Sum = summation of two hex digits  
• If Sum is greater than or equal to 16  
– Sum = Sum – 16 and Carry = 1  
• Example:  
carry:  
1 1  
1
1 C 3 7 2 8 6 A  
9 3 9 5 E 8 4 B  
A + B = 10 + 11 = 21  
Since 21 ≥ 16  
Sum = 21 – 16 = 5  
Carry = 1  
+
A F C D 1 0 B 5  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
14  
dce  
2015  
Signed Integers  
• Several ways to represent a signed number  
– Sign-Magnitude  
– Biased  
– 1's complement  
– 2's complement  
• Divide the range of values into 2 equal parts  
– First part corresponds to the positive numbers (≥ 0)  
– Second part correspond to the negative numbers (< 0)  
• Focus will be on the 2's complement representation  
– Has many advantages over other representations  
– Used widely in processors to represent signed integers  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
15  
dce Two's Complement Representation  
2015  
Positive numbers  
8-bit Binary Unsigned Signed  
value  
value  
value  
Signed value = Unsigned value  
00000000  
00000001  
00000010  
0
1
2
0
+1  
Negative numbers  
+2  
Signed value = Unsigned value – 2n  
. . .  
. . .  
126  
127  
128  
129  
. . .  
. . .  
+126  
+127  
-128  
-127  
. . .  
n = number of bits  
01111110  
01111111  
10000000  
10000001  
. . .  
Negative weight for MSB  
Another way to obtain the signed  
value is to assign a negative weight  
to most-significant bit  
1 0 1 1 0 1 0 0  
11111110  
11111111  
254  
255  
-2  
-128 64 32 16  
8
4
2
1
-1  
= -128 + 32 + 16 + 4 = -76  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
16  
dce  
2015  
Forming the Two's Complement  
00100100 = +36  
11011011  
starting value  
step1: reverse the bits (1's complement)  
step 2: add 1 to the value from step 1  
sum = 2's complement representation  
+
1
11011100 = -36  
Sum of an integer and its 2's complement must be zero:  
00100100 + 11011100 = 00000000 (8-bit sum) Ignore Carry  
Binary Value  
Another way to obtain the 2's complement:  
least  
significant 1  
= 00100100  
2's Complement  
= 11011100  
Start at the least significant 1  
Leave all the 0s to its right unchanged  
Complement all the bits to its left  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
17  
dce  
2015  
Sign Bit  
• Highest bit indicates the sign  
• 1 = negative  
Sign bit  
• 0 = positive  
1
0
1
0
1
0
1
0
0
1
1
0
1
1
0
0
Negative  
Positive  
For Hexadecimal Numbers, check most significant digit  
If highest digit is > 7, then value is negative  
Examples: 8A and C5 are negative bytes  
B1C42A00 is a negative word (32-bit signed integer)  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
18  
dce  
2015  
Sign Extension  
Step 1: Move the number into the lower-significant bits  
Step 2: Fill all the remaining higher bits with the sign bit  
• This will ensure that both magnitude and sign are correct  
• Examples  
– Sign-Extend 10110011 to 16 bits  
10110011 = -77  
11111111 10110011 = -77  
– Sign-Extend 01100010 to 16 bits  
00000000 01100010 = +98  
01100010 = +98  
• Infinite 0s can be added to the left of a positive number  
• Infinite 1s can be added to the left of a negative number  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
19  
dce  
2015  
Two's Complement of a Hexadecimal  
• To form the two's complement of a hexadecimal  
– Subtract each hexadecimal digit from 15  
– Add 1  
• Examples:  
2's complement of 6A3D = 95C2 + 1 = 95C3  
2's complement of 92F15AC0 = 6D0EA53F + 1 = 6D0EA540  
2's complement of FFFFFFFF = 00000000 + 1 = 00000001  
• No need to convert hexadecimal to binary  
Computer Architecture – Chapter 3  
© Spring 2015, CE  
20  
Tải về để xem bản đầy đủ
pdf 39 trang Thùy Anh 15120 Free
Bạn đang xem 20 trang mẫu của tài liệu "Bài giảng Kiến trúc máy tính - Chương 3, Phần 1: Data representation - Võ Tấn Phương", để tải tài liệu gốc về máy hãy click vào nút Download ở trên

File đính kèm:

  • pdfbai_giang_kien_truc_may_tinh_chuong_3_phan_1_data_representa.pdf