将十进制转化为八进制的算法
Converting a number from Decimal to Octal is almost similar to converting Decimal into Binary, although just one difference is that unlike Binary conversion, here in an integral part, we successively divide the number by 8 until the quotient is 0 (the last remainder becomes the MSB). The remainders read from bottom to top give the equivalent octal integer number. and in the fractional part, we multiply it by 8 till the fractional part of the product is 0. The first integer in the product term gives the MSB, thus the integers read from top to bottom gives the equivalent octal fraction.
将数字从十进制转换为八进制几乎类似于将十进制转换为二进制 ,尽管唯一的区别是与二进制转换不同,在整数部分中,我们将数字连续除以8直到商为0(最后的余数变为MSB)。 从下到上读取的余数给出等效的八进制整数。 在小数部分中,我们将其乘以8,直到乘积的小数部分为0。乘积项中的第一个整数给出MSB,因此从上到下读取的整数给出等效的八进制小数。
Same as in decimal to binary conversion, to convert a mixed decimal number into octal, we first separate the integral and the fractional part and then convert them into octal individually, after converting both to octal separately, we combine them back together to get the desired result.
与十进制转换为二进制一样 , 要将混合的十进制数转换为八进制 ,我们首先将整数和小数部分分离,然后将它们分别转换为八进制,分别将其转换为八进制后,将它们组合在一起即可得到所需的值结果。
Example 1:
范例1:
Convert (73.625)10 to ( ? )8
将(73.625) 10转换为(?) 8
Solution:
解:
Firstly, we will separate the integral part (73)8 and the fractional part (0.625)8. Now, we will convert each of them to octal individually.
首先,我们将积分部分(73) 8和小数部分(0.625) 8分开。 现在,我们将它们分别转换为八进制。
Integral Part
整体部分
Divisor | Quotient | Remainder |
---|---|---|
8 | 73 | |
8 | 9 | 1 LSB |
8 | 1 | 1 |
8 | 0 | 1 MSB |
除数 | 商 | 余 |
---|---|---|
8 | 73 | |
8 | 9 | 1 LSB |
8 | 1个 | 1个 |
8 | 0 | 1个MSB |
All the remainders read from top to bottom, where topmost is the LSB and bottom one is the MSB.
所有其余部分从上至下读取,其中最高的是LSB,最低的是MSB。
Therefore, (73)10 = (111)8
因此,(73) 10 =(111) 8
Fractional Part
小数部分
0.625 * 8 = 5.000
The integer part of the product term read from top to bottom forms the equivalent octal number i.e., (.625)10 = (0.5)8
从上到下读取的乘积项的整数部分形成等效的八进制数,即(.625) 10 =(0.5) 8
After converting both integral part and fractional part individually into octal, now we combine both to get our desired result i.e., (73.625)10 = (111.5)8
将整数部分和小数部分分别转换为八进制后,现在我们将两者合并以获得所需的结果,即(73.625) 10 =(111.5) 8
Example 2:
范例2:
Convert (965.198)10 to ( ? )8
将(965.198) 10转换为(?) 8
Solution:
解:
Integral Part
整体部分
Divisor | Quotient | Remainder |
---|---|---|
8 | 965 | |
8 | 120 | 5 LSB |
8 | 15 | 0 |
8 | 1 | 7 |
8 | 0 | 1 MSB |
除数 | 商 | 余 |
---|---|---|
8 | 965 | |
8 | 120 | 5 LSB |
8 | 15 | 0 |
8 | 1个 | 7 |
8 | 0 | 1个MSB |
The remainders read from bottom to top gives the equivalent octal number i.e., (965)10 = (1705)8.
从下到上读取的余数给出等效的八进制数,即(965) 10 =(1705) 8 。
Fractional Part
小数部分
0.198 * 8 = 1.584 MSB
0.584 * 8 = 4.672
0.672 * 8 = 5.376
0.376 * 8 = 3.008
0.008 * 8 = 0.064
0.064 * 8 = 0.512 LSB
The integer part of the product term read from top to bottom forms the equivalent octal number i.e., (0.198)10 = (0.145300)8.
从上到下读取的乘积项的整数部分形成等效的八进制数,即(0.198) 10 =(0.145300) 8 。
After converting both integral part and fractional part individually into octal, now we combine both to get our desired result i.e., (965.198)10 = (1705.145300)8
将整数部分和小数部分分别转换为八进制后,现在我们将两者合并以获得所需的结果,即(965.198) 10 =(1705.145300) 8
Example 3:
范例3:
Convert (296.225)10 to ( ? )8
将(296.225) 10转换为(?) 8
Solution:
解:
Integral Part
整体部分
Divisor | Quotient | Remainder |
---|---|---|
8 | 296 | |
8 | 37 | 0 LSB |
8 | 4 | 5 |
8 | 0 | 4 MSB |
除数 | 商 | 余 |
---|---|---|
8 | 296 | |
8 | 37 | 0 LSB |
8 | 4 | 5 |
8 | 0 | 4个MSB |
The remainders read from bottom to top gives the equivalent octal number i.e., (296)10 = (450)8.
从下到上读取的余数给出等效的八进制数,即(296) 10 =(450) 8 。
Fractional Part
小数部分
0.225 * 8 = 1.80 MSB
0.80 * 8 = 0.64
0.64 * 8 = 5.12
0.12 * 8 = 0.96
0.96 * 8 = 7.68 LSB
The integer part of the product term read from top to bottom forms the equivalent octal number i.e., (0.198)10 = (0.10507)8.
从上到下读取的乘积项的整数部分形成等效的八进制数,即(0.198) 10 =(0.10507) 8 。
After converting both integral part and fractional part individually into octal, now we combine both to get our desired result i.e., (296.225)10 = (450.10507)8.
在将整数部分和小数部分分别转换为八进制之后,现在我们将两者合并以获得所需的结果,即(296.225) 10 =(450.10507) 8 。
翻译自: https://www.includehelp.com/basics/conversion-of-decimal-number-system-into-octal-number-system.aspx
将十进制转化为八进制的算法