Decimal with binary, octal, hexadecimal conversion

Source: Internet
Author: User

(a) the numbering

The computer is binary, because the binary has simple operation, easy to achieve and reliable, for the logical design provides a favorable way to save equipment and other advantages, in order to facilitate the description, but also commonly used eight. 16 binary as the binary abbreviation. Characteristics:

(1) every n into one, n is the number of symbols required for each carry-in number to denote a base.

Binary: Every two in one, borrow one when two

Octal: Every eight into one, borrow one when eight

Hex: Every 16 in one, borrow one when 16

(ii) The conversion of the numbering

The principle of conversion between different carry counts: the conversion between different carry counts is based on the principle that two rational numbers are equal, then the integers of two numbers and fractional parts must be equal respectively.

Decimal: There are 10 cardinality: 0,1,2,3,4,5,6,7,8,9

Binary: There are two cardinality: 0,1

Octal: There are eight cardinality: 0,1,2,3,4,5,6,7

Hex: There are 16 cardinal numbers: 0,1,2,3,4,5,6,7,8,9,a (Ten), B (one), C (), D (+), E (+), F (15)

(c) Conversion of decimal and binary binary

<1> decimal--Binary

The decimal number is divided by 2, and the remainder is written in the opposite direction except to 0 o'clock, which is the binary number

Example: 36 divided by 2 to conclude that the quotient is 18 9 4 2 1

The resulting remainder is 0 0 1 0 0 1

Write the remainder from right to left as 1 0 0 1 0 0

The resulting 100100 is a binary number

<2> Binary--Decimal

Calculation formula: a*2^0+b*2^1+c*2^2+......+m*2^ (n-1) =

In the above formula, a represents the first digit to the right of the binary number, B represents the second right of the binary number, and C indicates the third right of the binary number ... m represents the right-hand (n-1) digits of the binary.

Example: 1011011 (2) =89

1*2^0+0*2^1+0*2^2+1*2^3+1*2^4+0*2^5+1*2^6

=1+8+16+64

=89

(d) Conversion of decimal and octal systems

<1> decimal--eight binary

The decimal number is divisible by 8 until the quotient is 0, and the resulting remainder is written in the reverse order, which is the octal binary.

Example: 49 divided by 8 to obtain a remainder of 1 6

Remainder is written from right to left as 61

49=61 (8)

<2> octal--Decimal

Calculation formula: a*8^0+b*8^1+c*8^2+......+m*8^ (n-1) =

In the above formula, a represents the first digit to the right of the octal number, B represents the second digit to the right of the octal number, and C indicates the third digit to the right of the octal number ... m represents the right (n-1) digit of the octal.

Example: 2137 (8) =1119

7*8^0+3*8^1+1*8^2+2*8^3

=7+24+64+1024

=1119

(v) Decimal and hexadecimal conversions

<1> decimal--16 binary

The decimal number is divisible by 16 until the quotient is 0, and the resulting remainder is written in the reverse order, which is 16 binary.

Example: 75 divided by 16 to obtain the remainder of one (B) 4

Remainder is written from right to left as 4B

<2> hex--Decimal

Calculation formula: a*16^0+b*16^1+c*16^2+......+m*16^ (n-1) =

In the above formula, A is the first digit to the right of the hexadecimal number, B is the second digit to the right of the hexadecimal number, and C is the third digit to the right of the hexadecimal number ... m represents the right (n-1) number of hexadecimal digits.

Example: 1BC2 (16) =7106

2*16^0+12*16^1+11*16^2+1*16^3

=2+192+2816+4096

=7106

(vi) binary with octal, hexadecimal conversion

Binary conversion to octal: for integers, use right-to-left every three-bit group, not enough three bits on its left to 0, each group is converted separately, that is, eight decimal.

Example: (001 101 111 011)

1 5 7 3

1101111011 (2) =1573 (8)

octal to binary: The conversion is done by replacing each octet with a three-bit binary number.

Example: (1 7 3 5)

001 111 011 101

1735 (8) =1111011101 (2)

Note: 001 (2) =1 (8) 010 (2) =2 (8) 011 (2) =3 (8) 100 (2) =4 (8) 101 (2) =5 (8) 110 (2) =6 (8) 111 (2) =7 (8)

Binary conversion to 16: for integers, use a right-to-left every four-bit group, not enough four-bit to the left of the 0, each group is converted separately, that is, eight binary number.

Example: (1001 0111 0111 1001)

9 7 7 9

100101110111101 (2) =9779 (16)

16 binary to binary: the conversion can be done by replacing each hexadecimal bit with a four-bit binary number.

Example: (8 7 6 5)

1000 0111 0110 0101

8765 (16) =1000011101100101 (2)

Note: 0001 (2) =1 (16) 0010 (2) =2 (16) 0011 (2) =3 (16) 0100 (2) =4 (16) 0101 (2) =5 (16)

0110 (2) =6 (+) 0111 (2) =7 (+) (2) =8 (+) 1001 (2) =9 (+) 1010 (2) =a (16)

1011 (2) =b (+) 1100 (2) =c (+) 1101 (2) =d (+) 1110 (2) =e (+) 1111 (2) =f (16)

Decimal with binary, octal, hexadecimal conversion

Contact Us

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.