Chapter III Information Coding and data representation (I.)

Source: Internet
Author: User

Chapter III Information Coding and data representation I. Basic concept of carry count value

cardinality R
Refers to the number of basic digits allowed in this rounding system. A system with a base of R is called an R-binary number. The main feature of the R-number is that every R enters 1

Right WI
The right, also known as the right, refers to the weight value of the digital on an I, which is related to the position of the digital. Wi =ri.

Assume that any number n is represented by an R-binary number in the form:
N= (Dm-1dm-2 ... D0. D-1d-2 ... D-K) R
Where Di is the basic symbol of the binary, di∈[0,r-1],i =-K,-k+1, ..., m-1; the decimal point is between D0 and D-1.

(11011.011) 2=1x24+ 1x23+ 0x22+1x21+ 1x2-0+ 0x2-1 + 1x2-2 + 1x2-3= (27.375) 10

(2345.459) 10=2x103+ 3x102+ 4x101+5x100+ 4x10-1+ 5x10-2+ 9x10-3

Two. Different binary conversions common in # # #:

The decimal (decimal), binary (binary), octal (octal), hexadecimal (hexdecimal) numbers are marked by D, B, Q, H, respectively.
* Example *
(2B.D) 16= (2B.D) h= (43.8125) 10= (53.64) Q

Other conversions into decimal:

right-weighted expansion, weighting sum

Example
(5ac.e6) 16= 5x162+ 10x161 +12x160 +14x16-1+ 6x16-2 = (1452.8984375) 10

Decimal into binary, octal, 16 binary:

Conversion Method : Can be divided into the following two ways
Direct conversion : decimal → binary, 86 or 16 binary
Indirect conversions : decimal → binary → 86 or 16 binary

    • Decimal →r Binary

Conversion Method
integer part : Divide by R to get the remainder, first low, until the quotient is 0.
The number of parts : by R rounding, first get high, until the product is 0 or to achieve the accuracy requirements.
Example :

(123.75) 10 = (173.6) 8

When the decimal part cannot be divisible into binary, the product will not be 0 when multiplied by 2 rounding, or when the decimal part is converted to a bits number, then the bits number is determined by the precision.

If the required accuracy is greater than 10%, the absolute value of the difference between the left and right decimal values of "=" is <10%.
That is, 10%>2-n
So n=4

    1. Binary → eight, hex
      Binary → octal
      The decimal point is divided into two sides, each of three groups, write the corresponding octal number. (Not enough digits on both sides plus 0 to complement 3-bit)
      binary → hexadecimal
      The decimal point is divided into two groups, each four-bit group, write the corresponding hexadecimal symbol. (Not enough digits on both sides plus 0 to complement 4-bit)
      Example
      (1011111.11) 2= (137.6) 8= (5F. C) 16
    2. octal binary → Binary
      Expand each octet number to a 3-bit binary number, and 0 of the highest and lowest bits can be omitted.
    3. Hex → Binary:
      Expand each hexadecimal number to a 4-bit binary number, and 0 of the highest and lowest bits can be omitted.
      Example
      (765.23) 8 = (111 110 101.010 011) 2
      (765.23) 16 = (111 0110 0101.0010 0011) 2

Why do binary representations of data be used in computers?
1. Physical devices with two-valued states are easy to implement.
2. Binary operation rules are simple, hardware implementation is easy.
3. Have logical characteristics, can represent "true and false", "right and wrong".
4. Strong anti-jamming capability and high reliability

Three. Encoding of the decimal number

How do I use binary to represent decimal data within my computer?
(1) Two-decimal code (BCD code)
(2) How to represent a decimal number string

BCD (Binary Coded Decimal) code:

Use binary to encode decimal digit 0~9.
Coding Method :
A 4-bit binary encoding is generally used to represent 1-bit decimal digits, and 10 are selected in 16 encodings to represent the digital 0~9. Different options make up a different BCD code.
category :

    • Right Code :

Each bit of the encoding has a fixed weight, and the weighted sum value is the decimal number represented. such as 8421 yards, 2421 yards, 5211 yards, 4311 yards, 84-2-1 yards and so on.

    • Unauthorized Code :

Each bit of code does not have a fixed right, mainly including Gray code, 3 yards and so on.

How to represent a decimal number string

string Form :
Use ASCII code to denote decimal digits or sign bits, or 1 bytes to hold 1-bit decimal digits or sign bits.
compressed decimal number string form :
The decimal number is represented by a BCD code, that is, 1 bytes holds 2 decimal digits, and the sign bit is placed after the lowest digit digits, usually C (12) is used for the positive sign, and D (13) for the minus.
For example +258 is represented as 258CH, occupies two bytes, 34 is represented as 034DH, and also occupies two bytes.
Common denominator :
It must be given its first address and bit length in main memory.

The advantages of using decimal to represent data are:

For the need for a large number of input and output data and simple operation, greatly reducing the 10 → Two and two → Ten conversion, improve the efficiency of the machine operation;
The bit length of the decimal string is variable, and many machines specify the length from 0 to 31, some even longer. It is not constrained by the uniform format of fixed-point and floating-point number, which improves the representation range and precision of data.

Data format

There are two types of data that are involved in the operation of a computer:

    1. unsigned data (Unsigned)
      All binary data bits are used to denote the value itself, with no positive or negative points.

    2. Signed data (Signed)
      Binary data bits, including sign bits and value bits. The signed data in the computer is also called the number of machines.

Number of machines

Code the "+", "-" symbols, and save the data in the computer.
number of machines features :

    1. The range of machine numbers is limited by the word length of the machine.
    2. The symbol must be numeric.
    3. The decimal point of the number of machines is expressed in the implied form of regulation.
Truth:

Refers to the number of machines that are truly represented by a value, denoted by a "+", "-" notation.

The coding method of machine number

: Original code, anti-code, complement, shift code.

How do computer hardware differentiate between unsigned and signed data?
Depending on the execution of the different instructions

how to represent a decimal point
In the number of machines, the decimal point and its position are implicitly defined; There are two implicit ways:
Fixed point number : The position of the decimal point is constant
Floating point number: The position of the decimal point is floating
fixed-point machine number is divided into fixed-point decimal, fixed-point integer two.
The position of the decimal point of the number of float machines is defined by the Order code and is therefore floating.

The position of the decimal point of the number of fixed- point machines is fixed, and can be divided into two types:
fixed-point decimals : Used to denote decimal fraction, the decimal point is implicitly fixed to the left of the highest data bit, and the integer digits are used to denote the sign bit.
fixed-point integer : Used to represent a pure integer, the decimal position is implicitly fixed after the lowest bit, and the highest bit is the sign bit.

Original code notation

Representation Method :
The highest bit represents the number of symbols, and the other bits represent the numeric digits.
sign bit :
0--positive, negative.
Value bits :
Is the same as the absolute value .
Example
Example 1:x=1011,y=-1011, then:
[X] Original =0,1011; [Y] original = 1,1011;
Example 2:x=0.1101,y=-0.1101, then:
[X] Original =0.1101; [Y] original = 1.1101;
Example 3:x=1011, y=-0.1101, for X and Y 8-bit original number of machines.
[X] Original =0,0001011; [Y] original = 1.1101000;
0 of the expression :
0 of the original code indicates that there are two forms, that is, in terms of positive and negative numbers respectively.
[+0] Original = 00 ... 0 [-0] Original = 10 ... 0
Representation range : For n+1 bits the number of machines x, it can represent the range of data:
Fixed-point integer:-(2^n-1) ≤x≤2^n-1
Fixed-point decimal:-(1-2^-n) ≤x≤1-2^-n
Overflow: When the machine encounters a range of data that exceeds its number of machines

Anti-code representation

Representation Method :
The highest bit represents the number of symbols, and the other bits represent the numeric digits.
sign bit :
0-positive, 1-negative.
Value bits :
Positive numbers are the same as absolute values, negative values are reversed .
x=1011,y=-1011, then:
[X] anti = 0,1011; [Y] anti-=1,0100;
Example 2:x=0.1101,y=-0.1101, then:
[X] Anti-=0.1101; [Y] anti = 1.0010;
Example 3:x=1011, y=-0.1101, the number of 8-bit anti-code machines for X and Y.
[X] Anti-=0,0001011; [Y] anti = 1.0010111;
0 of the expression :
There are two types of anti-code representations in 0, namely, positive and negative numbers.
[+0] anti = 00 ... 0 [-0] anti = 11 ... 1
indicates the range :
For the n+1-bit inverse machine number x, it can represent a range of data:
fixed-point integers :
-(2^n-1) ≤x≤2^n-1
fixed-point decimals :
-(1-2^-n) ≤x≤1-2^-n

The complement indicates

Representation Method :
The highest bit is the sign bit, and the other bits are numeric digits.
sign bit :
0-positive, 1-negative.
Value bits :
Positive number, the same as the absolute value, negative, when the absolute value is reversed, the bottom plus 1.
Simple Algorithm :
Negative time, from the back to look forward, encountered the first 1, this 1 and after the 1 unchanged, the front of the reverse.
Example
Example 1:x=1011,y=-1011, then:
[X] complement = 0,1011;[y] complement =1,0101;
Example 2:x=0.1101,y=-0.1101, then:
[X] complement = 0.1101;[y] complement =1. 0011;
Example 3:x=1011, y=-0.1101, the number of 8-digit complement machines for X and Y.
[X] complement = 0,0001011;[y] complement = 1.0011000;
0 of the expression :
The 0 complement representation is unique , that is, the positive and negative representations are consistent, and are all zeros.
[+0] complement = 00 ... 0 [-0] complement = 00 ... 0
indicates the range :
For the n+1-complement machine X, the range of data it can represent is:
fixed-point integers :
-2^n≤x≤2^n-1
Fixed-point decimals: -1≤x≤1-2^-n
The integer data (int) in the computer is expressed in the form of complement.

Shift Code Representation

Representation Method :
The highest bit is the sign bit, and the other bits are numeric digits.
sign bit :
1-positive, 0-negative.
Value bits :
Positive number, the same as the absolute value, negative, when the absolute value is reversed, the bottom plus 1.
That is , when negative, the symbol position of the complement is reversed
Example
Example 1:x=1011,y=-1011, then:
[X] Shift =1,1011; [Y] Shift =0,0101;
Example 2:x=0.1101,y=-0.1101, then:
[X] shift = 1.1101; [Y] shift = 0.0011;
Example 3:x=1011, y=-0.1101, the number of 8-bit code-shifting machines for X and Y.
[X] Shift =1,00001011;[y] shift = 0.00110000;
0 of the expression :
0 of the code is unique , that is, the positive and negative representations are consistent.
[+0] Shift = 10 ... 0 [-0] shift = 10 ... 0
indicates the range :
For the N+1 Displacement Code machine number x, it can represent a range of data:
fixed-point integers :
-2^n≤x≤2^n-1
fixed-point decimals :
-1≤x≤1-2^-n
The shift code is usually used as the order of the floating-point number, which is generally only represented by fixed-point integers.

Fixed-point machine number conversion

number of machines converted to truth
the key points for converting four fixed-point machines to true values are :
first of all , according to the symbol of the number of machines to determine the positive or negative value, and then against the definition and representation of the machine number, the opposite direction to find the absolute values of truth
conversion of machine numbers to each other
The simplest way to convert between the original code, the complement, the inverse code and the shift code is to find out their true value First and then convert it to another representation method.

Example

Chapter III Information Coding and data representation (I.)

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.