About those things hex and binary conversion

To understand hex and binary conversion, you first need to understand number systems.

A computer-system comprising a number of commonly used :( number systems)

Decimal number system (every one decimal)

The binary number system (every binary one)

Octal number systems (every octal a)

Hexadecimal number systems (every hex a)

 

 

 

Daily life, we will often encounter other number systems, such as 60 seconds to 1 minute (60 hex), 12 months for 1 year (12 hex), the fourth quarter of one year (4-ary) .

We sort out the characteristics of number systems, basic concepts are summarized as follows:

1. Digital: as decimal 0, 1, 2, 3, 4, 5, 6, 7, 8, 9; in binary 0, 1; 16 in hexadecimal 0-9, A, B, C, D, E, F

2. Base: number of digits of the number system used. The binary radix 2.

3. The bit weights: a number system on a size of a value (which value position) Fig.

E.g:

1, the right position for the decimal 123,1 100 (102), the bit weight 2 10 (101), bit 3 is a right (100). Press the right expands to:

123)10 = 1 × 102 + 2 × 101 + 3 × 100

2, the bit weights are octal 234,2 64 (82), the right 3 bits is 8 (81), bit 4 is the right one (80)

Other so-ary

Conversion between hexadecimal:

1, turn the other binary decimal: Press the right Expand

Calculation: (285) 9 = 10 (?)

2 × 92 + 8 × 91 + 5 × 90 = 162 + 72 + 5 = 239

Answer: (285) = 9 (239) 10

2, the other transfer Decimal Hex: Short division

3、 (9527)10 = ( ? )8

4、

 

 

5. Answer: (9527) = 10 ( 22467 ) 8

(9531)10 = ( ? )16

 

 


(9531) 10 = ( 253B ) 16

In the future, when confronted with the transition between two non-decimal, the decimal can be used as an intermediate ramp, by fractional calculation.

3, the other band (with decimal) transfected decimal

(F8C.B)16 = ( ? )10

= F × 162 + 8 × 161 + C × 160 + B × 16-1

= 3840 + 128 + 12 + 0.6875

= 3980.6875

4, the decimal turn non-metric (decimal)

The integer portion the same as above, key is the fractional part (by-yl rounding method): a decimal number system multiplied by the target base, the first multiplication result to the integer part of the highest bit of the destination, which is then multiplied by the fractional portion of the base the integer part of a note sequence, repeatedly proceed until the fractional part is "0" or up to meet accuracy requirements.

(3980.6875)10 = ( ? )16

– 0.6875 × 16 = 11

– 11 -> B

3980 transformed into Hex F8C, plus B after the decimal point, eventually obtained the following results:

(3980.6875)10 = (F8C.B)16

"8421" conversion method

"Every binary one," we put the power of n 2 are listed according to the principle of the binary are:

20 = 1

21 = 2

22 = 4

23 = 8

Principle "8421" method that white is a kind of make up process, the value listed in the n-th power of 2, a "make up" depending on the situation.

** a, converted to a decimal number for binary **

For example: a binary number is converted to decimal number 1010

1010)2 = (1 × 8 + 0 × 4 + 1 × 2 + 0 × 1)10 = (10)10

** II is converted into a binary number to decimal **

Example: 10 decimal number into a binary number

10 may be composed of 8421 because of 2 and 8, 8 and 2 so that both are below 1 conspire, no leans on 0

8421 (10 = 8 + 2)↓

(1010)2

Example: converting decimal number into a binary number 6

8421 (6 = 4 + 2)

(0110)2

2 and 4 below all conspire is 1, 0 is not conspire

Example: 28 decimal to binary conversion

16 8421 (16 + 4 + 8 = 28)

1 1100

The numbers above 1 bit conspire, no conspire 0

(28)10 = (11100)2

** Third, for between hexadecimal and binary number conversion **

Since 8 + 4 + 2 + 1 = 15, with 0 exactly hexadecimal 4-bit binary number corresponds exactly to a hexadecimal number, also a hexadecimal number may correspond directly to 4-bit binary number (8 hex is a 3-bit binary corresponds to decimal 8)

Example: (1010110) is converted to hexadecimal 2

0110,4 first filled into 0101-bit binary number corresponds to a hexadecimal, i.e.,

(0 × 23 + 1 × 22 + 0 × 21 + 1 × 20) = (0 × 8 + 1 × 4 + 0 × 2 + 1 × 1) = (5)16

(0 × 23 + 1 × 22 + 1 × 21 + 0 × 20) = (0 × 8 + 1 × 4 + 1 × 2 + 0 × 1) = (6)16

Final results: (1010110) 2 = (56) 16

Example: (15C) 16 = 2 (?)

=(0001 0101 1100)2

Each 4 bits corresponding to hexadecimal, 1,5, C corresponding binary above can be given by referring to the correspondence table ary easily obtained above results.

Dry notes more attention to micro-channel public number: the old nine school

Guess you like

Origin www.cnblogs.com/ljxt/p/11612944.html