Base conversion and the conversion of the original anti-code and complement

First, the binary conversion

  1, and the number of system code system

 

Common number system representation
Decimal Binary Octal Hex 8421BCD code
0 0 0 0 0000
1 1 1 1 0001
2 10 2 2 0010
3 11 3 3 0011
4 100 4 4 0100
5 101 5 5 0101
6 110 6 6 0110
7 111 7 7 0111
8 1000 10 8 1000
9 1001 11 9 1001
10 1010 12 A 0001 0000
11 1011 13 B 0001 0001
12 1100 14 C 0001 0010
13 1101 15 D 0001 0011
14 1110 16 E 0001 0100
15 1111 17 F 0001 0101

 

 

 

 

 

 

 

 

 

 

 

 

  1, conversion between binary and decimal

    Conversion principles: the right to expand by adding a binary number written in the form of a sum of the respective power of N, and decimal calculation result.

    (10111101)2 = 1x27+0x26+1x25+1x24+1x23+1x22+0x21+1x20 = (189)10

  2. Binary octal

        Binary ( . 1 110    110   111   011   100 ) = (166734) 8

        Octal 166 734

  3, Binary Hex

   Binary ( 1101    1001   1110   0100 ) 2 = (D9E4) 16

      Decimal 139144

      Hex D 9 E 4

4, Binary Code 8421bcd

  Binary 8421bcd code can not be transferred directly, usually the first binary number to decimal number, and then converted to bcd code

  (1101)= (13)10 = (0001 0011)bcd

5, M-ary conversion into a decimal

  Conversion principles: the right to expand by adding the M-ary number is written in the form of a sum of the respective power of N, and decimal calculation result.

  (5213)6 = 5 x 6+ 2 x 62+ 1 x 61+ 3 x 60 = (1186)10

6, the decimal conversion into N-ary

  Conversion principles: N down after decimal addition modulo (150) 10 = (226) 8

  

  

Second, the original anti-code and complement

  Binary numbers, the first bit is the sign bit, 1 for negative, 0 for positive

1, positive: anti-code and complement as the original code

2, negative:

    Original code: most significant bit is 1, followed by the absolute value of the binary number

    Inverted: the symbol bit constant data bit bitwise

    Complement: In its last bit inverted +1

3, computing

  在计算机中运算中,加减法是高频运算,使用同一个运算器,可以减少中间变量存储的开销,这样也降低了CPU内部的设计复杂度

  减去一个数等于加上这个数的负数

  两个正数正数相加时,按照二进制加法直接计算即可

  如果有负数参与计算时则要使用其补码来参与计算。

  例                 

             

          负数:最左一位表示负,右面七位按位取反+1   -(0000010)=-2

 

 

 

Guess you like

Origin www.cnblogs.com/haoyujun135/p/11257154.html