C programming language - binary conversion / data representation

The first part: hex conversion

Binary: constituted by 0 and 1 every 2 into an
octal: consists of 0-7 into 1 every 8
hex: a 0 ~ 9, A ~ F configuration, feed 1 every 16

Two basic concepts

Base: n-ary base is n

123.4 = 110^2 + 210^1 + 310^0 + 410^-1 

Bit right:
left of the decimal k-bit right as the base ^ k-1
k-bit right of the decimal point to the right as the base ^ -k

Other binary decimal turn (the right to expand by summation method)

Decimal = 123.4 1 10 ^ 2 + 10 ^ 3 1 + 10 ^ 0 + 4 10 ^ -1 
binary 1011.1 1 = 2 ^ 3 + 0 2 + 1 2 ^ 2 ^ 1 + 1 2 + 1 ^ 0 2 ^ - 1 = 11.5
octal 123.4 = 1
. 8 ^ 2 + 2 . 8 ^ 1 + 3 . 8 ^ 0 + 4 . 8 -1 = 83.5
hex = 123.4 1
16 2 + 2 16 ^ 1 + 3 16 + 4 ^ 0 -1 * 16 = 291.25

Decimal turn the other band

The integer part of: the base division, modulo reverse
fractional part: multiplying the base sequence Rounding
 
Decimal -> Binary
integer division modulo 2 reverse (in units of 4 bits, 0 is less than the high bit)
the decimal rounding by 2 positive sequence (met take an integer, decimal and then multiplied by 2)

Among other binary conversion

  1. Binary octal (3-bit binary octal = 1 corresponds to "421")
    01011010 == 132
    000 = 0100 = 4
    001 = 1101 = 5
    010 = 2110 = 6
    011 = 3111 = 7
     
  2. Binary hexadecimal (4-bit binary Hex = 1 corresponds to "8421")
    0101 1010 ==. 5A
    0000 1000 = 0. 8 =
    0001 = 1. 9 1001 =
    0010 A = 1010 = 2
    0011 = 1011. 3 = B
    0100 1100 is. 4 = C =
    0101. 5 = 1101 = D
    0110 = 1110. 6 E =
    0111. 7 = 1111 = F.

Part II: data representing

Classification shaping data

1. Unsigned integer: all bits represent the size.
Range Data N bit unsigned integer is represented by: 0. 1 ~ 2N-
 
2. Signed integer data: indicates the highest bit symbols: n is 0, 1 negative. Common original code, anti-code complement representation.

Positive: three yards the same.
 
Example: Given x = + 76D, three write code representation x (8)
Solution: x = + 76D = + 1001100B
as x> 0
Therefore: [x] = the original [x] trans = [x] = complement 01001100B
 
negative:
 
Example 1: known x = -76D, three write code representation x (8)
x = -76D = -1001100B: Solutions
[x] original 1001100B 1 = 
[x] trans = 1 0110011B (the original code negation)
[X] complement = 1 0110100B (plus a last one)
 
Example 2: Given: [X] original = [y] trans = [z] complement = 1100 1011B, calculated x, y, z of the magnitude relationship .
[x] of the original 1100 is 1011B X = -100 = 1011B
[Y] 1100 is trans 1011B =
[Y] 1011 0100B original Y = -011 = 0100B
[Z] 1011 0100B fill = 
[Z] Original = 1100 1100B z = -100 1100B
y> x> z

Guess you like

Origin www.cnblogs.com/chenxinshuo/p/11927292.html