# Computer Basics: Binary, octal, decimal, hexadecimal

Source: Internet
Author: User
Computer Basics: Binary, octal, decimal, hex 2006-11-29 20:23
one or 10 binary number

The decimal number is the most widely used counting system in daily life. The symbols that make up the decimal number have a total of 10 symbols such as 0,1,2,3,4,5,6,7,8,9, and we call these symbols digital.
In decimal, each digit has a total of 10 0~9, so the base of the count is 10. More than 9 must be represented by a number of digits. The operation of the decimal number follows: When adding: "Every ten into one"; Subtraction: "Borrow a ten".
In decimal numbers, the position of the digital is different, and the value represented is not the same.

formula, each corresponding digital has a coefficient 1000,100,10,1 corresponding to it, this coefficient is called the right or the right. The bit weights for decimal numbers are generally expressed as:10n-1

In the formula, 10 is the decimal carry base, 10 I is the right of the second position, N is the position of the decimal point, the integer is taken, and when N is on the left side of the decimal point, it takes n=1, 2, 3......N in turn. At the right of the decimal point, take N=-1,-2,-3 ... Therefore, 634.27 can be written as:

634.27=6x102+3x101+4x100+2x10-1+7x10-2

In the normal writing, the digital position is implied in the number of digits, that is, bits, 10, hundred and so on.

two or two binary

The information that the computer processes is the information that is represented only by the "0" and "1" Two simple numbers, or is encoded with such a number. This system is called binary. To understand computers, you first need to know how to represent the numbers in your computer.

In order to distinguish the number represented by different numbers, usually by the right enclosing another subscript number or letter to denote the system number, decimal numbers in D, binary with B, hexadecimal number with H, octal is denoted by O.

Binary calculation method Features: ① binary number only "0" and "1" two digital, the base is 2, the largest number is 1;② adopt the principle of every two into one.

The binary bit weights are generally expressed as: 2n-1. The power of each of you is the base of 2. For example, (01101010) The rights of each of you are from 27, 26, 25, 24, 23, 22, 21, 20, respectively.

The arithmetic arithmetic rule of binary number is the same as the decimal number except the input and borrow.
0+0=0 1+0=1
0+1=1 1+1=10 (red for carry bit)
Binary subtraction Rule
0-0=0 0-1=1-Borrow
1-0=1 1-1=0
Binary multiplication Rules
0x0=0 1x0=0
0x1=0 1x1=1

In order to distinguish it from the decimal number, the binary number can be represented in two ways when writing: for example: (1011.01) 2 or 1011.1B.

For example: Write out the decimal number expression (1011.01) 2.
(1011.01) 2=1x23+0x22+1x21+1x20+0x2-1+1x2-2= (11.25) 10

Binary has only "0" and "1" two numbers, it is easy to indicate. The high and low voltages, the cutoff and saturation of transistors, and the magnetization direction of magnetic materials can be expressed as "0" and "1" states.
Each of the binary numbers has only 0 and 12 states, only two devices are required to be able to represent, so the binary number saves the device. Because of the simple state, it has strong anti-jamming force and high reliability.

The main disadvantage of binary is that the digits are too long, inconvenient to read and write, and people are not used to it. This is commonly used in octal and hexadecimal notation as binary abbreviations. In order to adapt to people's habits, usually in the computer using a binary number, input and output in decimal numbers, by the computer to complete the conversion between binary and decimal.

36 or 16 binary number

Binary numbers are easy to handle in a computer system, but when the number of bits is more difficult to remember and write, in order to reduce the number of bits, the binary number is usually expressed in hexadecimal.
Hexadecimal is a computer system in addition to the binary number of the use of more than the binary, its counting method is characterized by:
① has a total of 16 digital 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f, respectively, corresponding to the decimal number of the 0~15;
The ②/borrow rule for adding and subtracting hexadecimal numbers is: borrow one when 16, every 16 into one.

The bit weights for hexadecimal numbers are generally expressed as: 16n-1. Where 16 is the hexadecimal carry base, and N represents the position of the relative decimal point. In writing, the hexadecimal number is represented by a raise of 16 or H, for example: (8fa.5) 16 or 8fa.5h.
For example: Write out the decimal number expression (8fa.5) 16.
(8fa.5) 16=8x162+15x161+10x160+5x16-1= (2298.3125) 10

four or eight binary number

The octal notation is characterized by:
There are eight different calculated symbols 0, 1, 2, 3, 4, 5, 6, 7, these eight symbols are called digital.
Adopt the principle of every eight into one. 　　Corresponds to the decimal number 0, 1, 2, 3, 4, 5, 6, 7, 8, eight binary numbers are recorded as 0, 1, 2, 3, 4, 5, 6, 7, 8, 10. The following table lists the binary and hexadecimal numbers corresponding to the decimal 0~16.

 Decimal number Binary number Hexadecimal number 0 0000 0 1 0001 1 2 0010 2 3 0011 3 4 0100 4 5 0101 5 6 0110 6 7 0111 7 8 1000 8 9 1001 9 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F 16 10000 10

Five, decimal number converted to non-decimal number

When a decimal conversion number is converted to a non-decimal number, it can be converted into integer and fractional parts, and the result is merged into the destination number.

Conversion of integer Parts
The conversion of integer parts is based on the method of removing the base. The so-called elimination of the basis of the method is to convert the base of the data to remove the integer part of the decimal number, the first addition to obtain the remainder of the goal number of the lowest bit, the resulting quotient is divided by the cardinality, the remainder of the goal number of the sub-low, and so on, continue the process until 0 o'clock, the remainder is the
Example converts a decimal 53D to a binary number (7-2).

53d=110101b

Conversion of fractional Parts
The conversion of the decimal part is based on the multiplicative base rounding method. The so-called multiplicative base rounding method is to use the decimal number to multiply the base of the purpose number, the integer portion of the result of the first multiplication is the highest bit of the fractional part of the destination number, its fractional part is multiplied by the cardinality, the integer portion of the result is the secondary high of the destination number, and so on, continues the above process until the fractional part is divided into 0 or to achieve the required precision.
It can be seen from the above that the number is converted to binary, although it has been known 5 times multiplied, but its decimal place also exists, because the topic requires the retention of 4 decimal places, the result is: 0.736d≈0.1011b or 0.736d≈0.1100b.

Six, non-ten numbers converted into decimal numbers

Since any number can be expanded by weight, it is easy to convert a non-decimal number to the corresponding decimal number. The specific steps are: to expand a non-decimal right into a polynomial, each of which is the digital and corresponding right of the product, the polynomial by the rules of the decimal number of the computer summation, the result is the number of decimal.

seven or two binary and hexadecimal number of mutual conversions

There are 16 combinations of four-digit binary numbers, and 16 combinations are exactly the same as the 16 combinations of hexadecimal, so each four-bit binary corresponds to one hexadecimal number, so the conversion between binary and hexadecimal is straightforward. Here are two examples of conversions:

From the above example, we can summarize the methods of two kinds of binary conversions:
★ Binary Conversion to 16 binary: As long as the integer portion of the binary number from right to left every four bits of a group, the last less than four bits of 0 to top up; fractional parts are left to right every four bits, and last less than four bits on the right by 0. The hexadecimal number corresponding to each four-bit binary number is then written.
★ Hexadecimal number converted to binary number is exactly the opposite, as long as the hexadecimal number of each bit corresponding to the four-bit binary written out to the right.

Common Coding

BCD Code

In a digital system, a variety of data to be converted to binary code to be processed, and people are accustomed to using decimal numbers, so in the input and output of the digital system still use the decimal number, so that a four-bit binary number to represent a decimal number method, This binary code, which is used to represent decimal numbers, is called a two-decimal code (binary Coded decimal), which is referred to as the BCD code. It has a binary number form to meet the requirements of the digital system, but also has the characteristics of the decimal (only 10 valid states). In some cases, computers can also operate directly on the number of this form. Common BCD codes are represented in the following ways. 8421BCD encoding

This is the most widely used BCD code, is a kind of power code, and the rights of each of them are (from the most effective high-level to the least significant bit) 8,4,2,1.
The example writes out the 8421BCD code corresponding to the 10-in number 563.97D.
563.97d=0101 0110 0011. 1001 01118421BCD
Example writes out the decimal number corresponding to the 8421BCD code 1101001.010118421BCD.
1101001.010118421BCD=0110 1001. 0101 10008421bcd=69.58d
When using 8421BCD code, be sure to note that its valid encoding is only 10, namely: 0000~1001. The remaining six encodings of the four-digit binary number 1010,1011,1100,1101,1110,1111 are not valid encodings. 2421BCD encoding

2421BCD code is also a kind of power code, its right from high to low to 2,4,2,1, it can also use four-bit binary number to represent a decimal number. Its encoding rules are shown in the following table. More than 3 yards

3 yards is also a BCD code, but it is not authorized code, but because each code corresponding to the 8421BCD code between 3, so called the remaining 3 yards, its general use is less, it is necessary to make general understanding, the specific code is the following table.

Common BCD Code tables

 Decimal number 8421BCD yards 2421BCD yards More than 3 yards 0 0000 0000 0011 1 0001 0001 0100 2 0010 0010 0101 3 0011 0011 0110 4 0100 0100 0111 5 0101 1011 1000 6 0110 1100 1001 7 0111 1101 1010 8 1000 1110 1011 9 1001 1111 1100 10 0001,0000 0001,0000 0100,0011

Gray Reflection code (cyclic code)

Gray code is an unauthorized code, it is characterized by any two adjacent yards between only a number of different. In addition, because the maximum number and the minimum number are only one number different, it is usually called gray Reflection code or cyclic code.

 Decimal number Binary number Gray Code Decimal number Binary number Gray Code 0 0000 0000 8 1000 1100 1 0001 0001 9 1001 1101 2 0010 0011 10 1010 1111 3 0011 0010 11 1011 1110 4 0100 0110 12 1100 1010 5 0101 0111 13 1101 1011 6 0110 0101 14 1110 1001 7 0111 0100 15 1111 1000

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.