Numeral Systems
In computers, besides binary, octal and hexadecimal are also commonly used.
Binary
Binary is the base system used in internal computer operations. In this system, there are only two digits: \(0\) and \(1\). All internal computer operations (including bitwise operations) are performed based on binary.
However, representing numbers in binary can make them very long. Therefore, for convenience of representation, binary numbers are often converted to octal or hexadecimal.
Octal
In octal, there are eight digits: \(0,1,2,3,4,5,6,7\).
Typically, octal numbers are represented in the form oxx (where o is the prefix for octal, and xx represents the octal number).
Hexadecimal
In hexadecimal, there are sixteen digits: \(0,1,2,3,4,5,6,7,8,9,A(10),B(11),C(12),D(13),E(14),F(15)\).
Compared to binary, the biggest advantage of hexadecimal is that it represents numbers with shorter lengths. One hexadecimal digit can represent 4 binary digits.
Typically, hexadecimal numbers are represented in the form 0xdbf (where 0x is the prefix for hexadecimal numbers).
Conversion Between Bases
Decimal to Binary/Octal/Hexadecimal
Here, binary is used as an example for demonstration. The principles for other bases are similar.
For the integer part, repeatedly divide the decimal number by 2 until the quotient is 0. Then, from bottom to top, take all the remainders as the integer part of the binary number. For the fractional part, multiply it by 2, take the integer part of the result, and then repeat the calculation with the resulting fractional part until the fractional part becomes 0. Then, from top to bottom, take all the integer parts obtained from the calculations as the fractional part of the binary number.
1 2 3 4 5 6 7 8 9 10 11 | |
Thus, \(35.25 = (100011.01)_2\)
Binary/Octal/Hexadecimal to Decimal
Again, binary is used as an example.
To convert a binary number to decimal, simply multiply the value of each digit by \(2^i\), where \(i\) is the position of the digit, starting from 0 for the units place.
1 2 3 | |
Thus, \((11010.01)_2 = (26.25)_{10}\)
Conversion Between Binary/Octal/Hexadecimal
One octal digit can be represented by 3 binary digits (since \(2^3 = 8\)), and one hexadecimal digit can be represented by 4 binary digits (since \(2^4 = 16\)), and vice versa.
本页面最近更新:,更新历史
发现错误?想一起完善? 在 GitHub 上编辑此页!
本页面贡献者:OI-wiki
本页面的全部内容在 CC BY-SA 4.0 和 SATA 协议之条款下提供,附加条款亦可能应用