Computer Logical Organization 简明教程
Codes Conversion
有许多方法或技术可以用来将代码从一种格式转换为另一种格式。我们将在本文中演示以下
There are many methods or techniques which can be used to convert code from one format to another. We’ll demonstrate here the following
-
Binary to BCD Conversion
-
BCD to Binary Conversion
-
BCD to Excess-3
-
Excess-3 to BCD
Binary to BCD Conversion
步骤
Steps
-
Step 1 — Convert the binary number to decimal.
-
Step 2 — Convert decimal number to BCD.
示例 − 将 (11101)2 转换为 BCD。
Example − convert (11101)2 to BCD.
Step 1 − Convert to Decimal
二进制数 − 111012
Binary Number − 111012
计算十进制当量 −
Calculating Decimal Equivalent −
Step |
Binary Number |
Decimal Number |
Step 1 |
111012 |
1 × 24) + (1 × 23) + (1 × 22) + (0 × 21) + (1 × 2010 |
Step 2 |
111012 |
(16 + 8 + 4 + 0 + 1)10 |
Step 3 |
111012 |
2910 |
二进制数 − 111012 = 十进制数 − 2910
Binary Number − 111012 = Decimal Number − 2910
BCD to Binary Conversion
步骤
Steps
-
Step 1 — Convert the BCD number to decimal.
-
Step 2 — Convert decimal to binary.
示例 − 将 (00101001)BCD 转换为二进制。
Example − convert (00101001)BCD to Binary.
Step 1 - Convert to BCD
BCD 数 − (00101001)BCD
BCD Number − (00101001)BCD
计算十进制等价物。将每四位数字转换为一组,并为每一组获取十进制等价物。
Calculating Decimal Equivalent. Convert each four digit into a group and get decimal equivalent for each group.
Step |
BCD Number |
Conversion |
Step 1 |
(00101001)BCD |
00102 10012 |
Step 2 |
(00101001)BCD |
210 910 |
Step 3 |
(00101001)BCD |
2910 |
BCD 数 − (00101001)BCD = 十进制数 − 2910
BCD Number − (00101001)BCD = Decimal Number − 2910
Step 2 - Convert to Binary
用于十进制到二进制转换的长除法方法。
Used long division method for decimal to binary conversion.
十进制数 − 2910
Decimal Number − 2910
计算二进制等价——
Calculating Binary Equivalent −
Step |
Operation |
Result |
Remainder |
Step 1 |
29 / 2 |
14 |
1 |
Step 2 |
14 / 2 |
7 |
0 |
Step 3 |
7 / 2 |
3 |
1 |
Step 4 |
3 / 2 |
1 |
1 |
Step 5 |
1 / 2 |
0 |
1 |
如步骤 2 和 4 中所述,余数必须按相反的顺序排列,以便第一个余数成为最低有效位数 (LSD),最后一个余数成为最高有效位数 (MSD)。
As mentioned in Steps 2 and 4, the remainders have to be arranged in the reverse order so that the first remainder becomes the least significant digit (LSD) and the last remainder becomes the most significant digit (MSD).
十进制数 − 2910 = 二进制数 − 111012
Decimal Number − 2910 = Binary Number − 111012
结果
Result
(00101001)BCD = (11101)2
BCD to Excess-3
步骤
Steps
-
Step 1 — Convert BCD to decimal.
-
Step 2 — Add (3)10 to this decimal number.
-
Step 3 — Convert into binary to get excess-3 code.
示例 − 将 (0110)BCD 转换为超额 3。
Example − convert (0110)BCD to Excess-3.
Excess-3 to BCD Conversion
步骤
Steps
-
Step 1 — Subtract (0011)2 from each 4 bit of excess-3 digit to obtain the corresponding BCD code.
示例 - 将 (10011010)XS-3 转换为 BCD。
Example − convert (10011010)XS-3 to BCD.
Given XS-3 number = 1 0 0 1 1 0 1 0
Subtract (0011)2 = 1 0 0 1 0 1 1 1
--------------------
BCD = 0 1 1 0 0 1 1 1
结果
Result
(10011010)XS-3 = (01100111)BCD