7. 十進位0.1的二進位表示法為何?
十進位0.1所對應的二進位數為無窮位數的
0.000110011…2
2-13
十六進位
A 4-bit pattern can be represented
by a hexadecimal digit,
and vice versa.
Bit Pattern Bit Pattern
Hex Digit Hex Digit
------------ ------------ ------------ ------------
0000 1000
0 8
0001 1001
1 9
0010 1010
2 A
0011 1011
3 B
0100 1100
4 C
0101 1101
5 D
0110 1110
6 E
0111 1111
7 F
2-14
7
8. Binary to hexadecimal and
Hexadecimal to binary transformation
2-15
二進位轉十六進位
二進位數換成十六進位數時,每四個位數合成一項
110110101.110112的十六進位表示法為1B5.D816
2-16
8
10. 八進位
A 3-bit pattern can be
represented
by an octal digit, and vice versa.
Bit Pattern Bit Pattern
Oct Digit Oct Digit
------------ ------------ ------------ ------------
000 100
0 4
001 101
1 5
010 110
2 6
011 111
3 7
2-19
Binary to octal and
Octal to binary transformation
2-20
10
12. Sign-and-magnitude integers
In sign-and-magnitude representation,
the leftmost bit defines the sign of the
number. If it is 0, the number is
positive.If it is 1, the number is negative.
2-23
帶正負符號大小表示法
Range: -(2N-1-1) … +(2N-1-1)
2-24
12
13. Sign-and-magnitude integers
Note:
There are two 0s in sign-and-magnitude
representation: positive and negative.
In an 8-bit allocation:
+0 00000000
-0 10000000
2-25
一補數表示法
給定一個十進位數值,轉換成它的一補數表示法
步驟如下:
步驟1 先忽略其符號,將數字的部分轉成二進位數值。
步驟2 若該二進位數值超過n - 1 個位元, 則為「溢位」
(overflow),無法進行轉換;否則在它的左邊補
0,直到共有n個位元為止。
步驟3 若所要轉換的數為正數或零,則上步所得數值即
為所求;若為負數,則將每個位元做補數轉換,
原為0的轉成1;原為1的轉成0。
Range: -(2N-1-1) … +(2N-1-1)
2-26
13
15. One’s complement integers
Note:
There are two 0s in one’s complement
representation: positive and negative.
In an 8-bit allocation:
+0 00000000
-0 11111111
2-29
One’s complement integers
Note:
In one’s complement representation,
the leftmost bit defines the sign of the number.
If it is 0, the number is positive.
If it is 1, the number is negative.
2-30
15
16. One’s complement integers
Note:
One’s complement means reversing all bits.
If you one’s complement a positive number,
you get the corresponding negative number.
If you one’s complement a negative number,
you get the corresponding positive number.
If you one’s complement a number twice, you
get the original number.
2-31
二補數表示法
給定一個十進位數值,轉換成它的二補數表示法
步驟如下:
步驟1 先忽略其符號,將數字的部分轉成二進位數值。
步驟2 若該二進位數值超過 n-1 個位元, 則為「溢位」
(overflow),無法進行轉換;否則在它的左邊補
0,直到共有n個位元為止;若所轉換的數為 -2n-
1,則轉出來的數為1後面有n-1個0,此即為該數的
二補數表示法,不應視為溢位。
步驟3 若所要轉換的數為正數或零,則上步所得數值即為所
求;若為負數,則最右邊的那些0及最右邊的第一個1
保持不變,將其餘的每個位元做補數轉換,原為0的
轉成1;原為1的轉成0。
Range: -(2N-1) … +(2N-1-1)
2-32
16
18. Two’s complement integers
Note:
In two’s complement representation,
the leftmost bit defines the sign of the number.
If it is 0, the number is positive.
If it is 1, the number is negative.
2-35
-40的二補數表示法正好是28-40
2-36
18
20. Two’s complement integers
Note:
There is only one 0 in two’s complement:
In an 8-bit allocation:
0 00000000
2-39
Two’s complement integers
Note:
Two’s complement can be achieved by reversing all
bits except the rightmost bits up to the first 1
(inclusive).
If you two’s complement a positive number, you get
the corresponding negative number.
If you two’s complement a negative number, you get
the corresponding positive number.
If you two’s complement a number twice, you get the
original number.
2-40
20
21. Addition in two’s complement
Note:
Rule of Adding Integers in
Two’s Complement
Add 2 bits and propagate the carry
to the next column. If there is a final
carry after the leftmost column
addition, discard it.
2-41
二補數表示法的兩正數相加
2-42
21
25. 為何二補數可以這樣做運算
正數 (x) + 負數 (-y)
-y在二補數表示值為 2n-y
得 2n+x-y
(1) x >= y
x-y為正值或0; 2n為進位
(2) x <y
2n+x-y = 2n-(y-x)
-(y-x)的二補數表示法
2-49
Changing fractions to binary
A floating-point number is an integer and a fraction.
Conversion floating-point number to binary
Convert the integer part to binary
Convert the fraction to binary
Put a decimal point between the two parts
Converting the fraction part
2-50
25
26. Example: Transform the fraction 0.875 to binary
Solution
Write the fraction at the left corner. Multiply the
number continuously by 2 and extract the integer
part as the binary digit. Stop when the number is
0.0.
0.875 1.750 1.5 1.0 0.0
.
0 1 1 1
2-51
正規化:Normalization
A floating-point number is normalized for a simple
representation
Normalization: the moving of the decimal point so
that there is only one 1 to the left of the decimal
point.
Original Number
Original Number Move Normalized
------------
------------ ------------ ------------
+1010001.1101 +26 × 1.01000111001
+1010001.1101 6
−111.000011 −22 × 1.11000011
-111.000011 2
+0.00000111001 +2−6 × 1.11001
+0.00000111001 6
−0.001110011 −2−3 × 1.110011
-001110011 3
2-52
26