# Data Representation and computation in the computer-1

Source: Internet
Author: User

1.1 Basic Components of computer systems

Computer hardware system:

Memory, controller, memory, input device, and output device

The host and controller components have been integrated into a central processor.

Calculator: Mainly used to complete arithmetic and logical operations.

Controller: Extracts commands from the primary memory for analysis.

Memory: Memory devices in computer systems, including Memory (Main Memory, MM) and external Memory

Memory (external storage ). The memory is used to temporarily store the programs, data, and intermediate results required for running the computer. Register

It is a memory device in the cpu used to temporarily store commands, data and calculation results. Compared with the memory, registers are much faster.

1.2 Data Representation and calculation in Computer

1.2.1 Data Representation in Computer

... In a computer, all kinds of information must be digitally encoded before being transmitted, stored, and processed,

The so-called encoding is to use a small number of basic symbols and use a certain combination principle to indicate a large number of complex

Diverse information, types of basic symbols, and combination rules of these symbols are two major elements of information encoding. For example, 26 English letters are used to represent English words. This is a typical example of encoding.

1. Carry counting system and its conversion

In a digital system that uses carry count, if only the r basic symbol is used to represent a value, it is called the r base,

R is the base of the number system. One statement: it is a counting method.

Commonly used input-number representation of computers:
Binary: returns the string B in the form of binary.

Octal character: O

Decimal: returns the decimal form. The decimal form is D.

Binary calculation rules:

* Addition 0 + 0 = 0 1 + 0 = 1 1 + 1 = 0;

* The Subtraction Method defaults to one when two 0-0 = 0; 1-0 = 1; 0-1 = 1;

* Multiplication: 0*0 = 0 1*0 = 0 1*1 = 0;

Calculation:

Convert decimal to binary

(175) 10 = (10101111) 2 -- divide "by 2 to obtain the remainder. The first obtained result is the lowest Bit.

(0.25) 10 = (0.01) 2-"multiply by 2 to get the integer. The first result is the highest bit.

0.25*2 .... 0; 0.5*2 .... 1; à 0. 01

(175.71875) 10 = (10101111.10111) 2à because the operation rules for integers and decimals are different

So we need to separate the operations and then add them together.

For example: 175 = 10101111

0.71857 = 0.10111

Convert binary to decimal;

(100110) 2 = 0*20 + 1*21 + 1*22 + 0*23 + 0*24 + 1*25 = (38) 10

(0.101) 2 = 1*2-1 + 0*2-2 + 1*2-3 = (0.625) 10

(100110.101) 2 = (38.625) 10

Decimal and octal Conversions

For example:

Convert decimal number 10 to octal number 12

Process: 10 (10) = 00001010 (2) = 12 (8)

Example:

Reverse request:

10 (8)-"? (2)

10 (8) = 00001000 (2) = 8 (10)

Decimal to hexadecimal conversion

10 (10)-"? (16)

10 (10) = 00001010 (2) = A (16)

So 12 (16 )--?? (10)

12 (16) = 00010010 (2) = 18 (2)

3. Number of machines and Code System

The data expressed in a computer is called the number of machines. The number of machines has no or no symbols.

For ease of operation, the number of machines with symbols can adopt different encoding methods, such as the original code, anti-code, and complement code. This is called the code system.

The highest digit indicates the most sign bit: 0 indicates the positive number, and 1 indicates the negative number,

The positive complement is the same as the reverse code.

Original code: the binary representation of the absolute value of an integer is called the original code.

Back code = back-to-source code

Complement = reverse code + 1;

The original code of zero value can be in the following two forms: + 0 = 00000000;-0 = 00000000;

There are two forms of anticode for zero value: + 0 = 00000000;-0 = 11111111;

Note: The symbol bit remains unchanged during the operation.

Convert the decimal number of negative numbers to binary

Example-3 (10)-"? (2)

(1 ). Obtain the original code: 00000011

(2 ). Returns the code 11111100.

(3). Get the completion code: 11111101, OK

If you want to get an octal system, three digits are merged into one digit. If you want to get a hexadecimal system, four digits are merged into one digit.

Assume that the machine font length is n = 8.

*** Code transfer Representation

The offset value is defined by adding an offset to the number X. It is often used to represent the level code in the floating point number. If the word length is n

In this case, you only need to reverse the signed bits to obtain the corresponding bitwise representation.

If the machine font is n = 8, the value is-1 (shift) = 01111111;

4. Floating Point Number

In decimal, a number can be written in multiple forms. For example, 83.125 can be written as 103*0.083125 or 104*0.0083125.

Similarly, a binary number can be written in multiple forms:

1011.10101 can be written as 24*0101110101, 25*0.0101110101

A binary number N containing the decimal point can be expressed

N = 2E * F

E is called the order code, and F is the ending number. This method of representing the number is called floating-point notation.

The number of floating point numbers is determined by the order code, and the precision is determined by the tail number.

Represented as a single-precision floating-point number of 176.0625 using the IEEE754 Standard

1. Convert to binary: 10110000.0001

2. Normalization: 1.01100000001x2 to the power of 7, which ensures that the highest bit is 1

3. Remove the most digit and extend it to the 23-digit ending number specified by the single-precision floating point number.

December 01100000001000000000000

4. Order Code; The exponent after the offset is 7 + 127 = 134

0 100011001100000001000000000000-"Single-precision floating point representation

** Encoding of decimal numbers and characters

A four-digit binary code is used to represent a decimal number. It is called binary encoding, BCD encoding for short.

Because the four times of 2 are equal to 16, and the decimal number is only 0-9,

Therefore, there are multiple BCD codes, which are divided based on whether each of the 4-bit codes has a definite permission,

It can be divided into two types: authorization code and authorization code.

** ASCII code:

US standard information interchange code

The low 4-bit d3d2d1d0 group is used as row encoding.

The high 3-bit group d6d5d4 is used as column encoding.

*** Chinese character encoding

Processing of Chinese characters includes encoding of Chinese characters input the storage of Chinese characters output

** Input code

It can be divided into three types: digital encoding, Pinyin code, and font code.

(1). number encoding. Digital encoding is a commonly used national standard location code that uses a string to represent the input of a Chinese character. The national standard location code will be published by the National Bureau of Standards

6763 Chinese Characters in two levels are divided into 94 areas, 94 characters in each area, and two 10-digit numbers are supported for each area. For example. The "medium" character is 48 characters in each 54-zone, and the location code is

5448.

(2). Pinyin code. Pinyin code is based on Chinese pronunciation. Because there are too many Chinese homophone characters and the input bit rate is very high

You must also select homophone, which affects the input speed.

(3 ). Font encoding. The font encoding is determined by the shape of Chinese characters. There are many Chinese Characters in total, but they are all made up of one stroke. The parts and strokes of all Chinese characters are limited.

. Therefore, you can encode the stroke parts of a Chinese character with letters or numbers and input them in the order of writing the strokes to indicate a Chinese character, a five-stroke shape, and a table code.

This encoding method is the most common input code.

2) Internal code

An internal Chinese character code (Chinese character internal code) is the most basic expression of Chinese characters in a device or information processing system. It is used to store, process, and transmit Chinese characters in a device or information processing system.

Code. The number of Chinese characters, can not be distinguished with one byte, the use of the National Standard bureau of GB2312-80 of Chinese characters, the two bytes are stored in the internal code of a Chinese character

The maximum position of each byte is 1, which is used as the inner code of the Chinese character machine. Because the two bytes each use 7 bits, they can represent 16384 differentiated inner-machine codes. The Chinese character "big" is used as an example.

The Country Code is 1 byte at the height of 3 h, and the inner code is B4F3H. + 8080!

3) A Chinese font is a data model that represents a Chinese font. It is usually represented by dot matrix, vector functions, and other methods.

This is the code of the Chinese Character Font matrix. The font code is also called the font Code. It is a Chinese Character Font Code represented by the dot matrix. It is the output method of Chinese characters,

According to the requirements of the output Chinese characters, the number of lattice characters varies. Simple Chinese characters are 16*16 arrays, high-precision Chinese characters are 24*24 lattice characters, 32*32 lattice characters

And 48*48 lattice.

* ** Basic logical operations

There are three basic operations in Logical Algebra:

AND Operation: Also known as logical multiplication, which is commonly expressed by AND other symbols.

Set A and B as two logical variables. The values of A and B are true only when the values of A and B are true,

Otherwise, the value is false.

OR operation: Also known as logical addition, whose operator numbers are usually expressed by OR.

Set A and B as two logical variables. if and only if the values of A and B are false, the values of A or B are false.

Otherwise, it is a real person.

Non-computation: Non-computation, also known as logic Inverse Calculation, is false. False is true.

Exclusive or operation: this operation is also called semi-plus operation. Common operators are called XOR.

Set A and B as two logical variables. if and only when the values of A and B are different, A is different or B is true,

The A-or B-operation can be represented by the first three basic operations.

Simplification of logical expressions:

* ***** Addition and subtraction of the number of machines

In a computer, you can set only the adder and perform the subtraction operation as an addition operation.

1. Original code addition and subtraction

When the number of original codes of the two identical symbols is added, you only need to add the value directly,

When the symbols of the two Addons are different, the subtraction operation should be performed. The method is: first compare the size of two absolute values.

And then subtract the absolute value of the absolute value from the absolute value smaller. The result symbol is a symbol with a large absolute value,

It is very troublesome to perform the subtraction operation on the number of machines indicated by the So original code. so computers are rarely used.

2. add and subtract Codes

The addition operation rule of the complement code is: the complement code equals the sum of the complement code, that is, [X + Y] = [X] + [Y]

The Subtraction Method of the complement code is: The difference of the complement code is equal to the completion code of the subtrahend plus the negative after the subtraction, that is, [X-Y] = [X] + [-Y]

The Method for Finding [-X] from [X] is as follows: all operators of [X] are reversed (including symbol bits), and 1 is added at the end.

Set the binary integer X = + 10000100, Y = + 1110, evaluate the value of X + Y, X-Y

Solution: 8-bit complement is used to represent signed data. Because X and Y are positive numbers, [X] fill = 010000100

[Y] fill = 00001110, then [-Y] Is = 11110010

Since X and Y are positive numbers, the value of X + Y is equal to [X] Complement + [Y] fill, that is, X + Y = + 1010010,

Set the binary integer X = + 110110, Y =-110011, evaluate the value of X + Y, X-Y

Solution: 8-bit complement is used to represent the symbol data.

Therefore, X fill = 00110110

Y complement = 11001101 -- "-Y fill = 00110001

Since X is a positive number, Y is a negative number, and the absolute value of X is greater than the absolute value of Y, the value of X + Y is equal to X-| Y |, that is, X + Y.

So X-Y = X + | Y |, that is equal to X +-Y

Addition and subtraction rules:

1. The operands involved in the operation are represented by the complement code.

2. the symbol bit is involved in the operation.

3. If the addition operation is performed, the complement codes of the two numbers are directly added. If the subtraction operation is performed, the subtraction side is the same as the symbol bit.

Add to subtrahend after 1 is reversed

4. The computation result is represented by a complement.

Compared with the original code subtraction operation, the process of the complement code subtraction operation is much simpler. In the complement code addition and subtraction operation, the symbol bit is the same as the numerical bit.

This operation requires no special processing. Therefore, most computers use the code addition and subtraction method.

4. The computation result is indicated by a complement code:

Compared with the original code subtraction operation, the process of the complement code subtraction operation is much easier. In the complement code addition and subtraction operation, the symbol bit is the same as the numerical bit.

This operation requires no special processing. Therefore, most calculations use the addition and subtraction operations.

3) overflow and determination

After determining the length of the operation and the representation of the data, the data range is also determined. Once the calculation result exceeds the data range that can be expressed

Overflow occurs. When overflow occurs, the calculation result is definitely incorrect.

The calculation result may overflow only when the two symbols are added or subtracted.

Set a positive integer X = + 1000001, Y = + 1000011. If the positive integer X = + is used

Then X fill = 01000001; Y fill = 01000011

Then: X fill + Y fill = 10000100;

The result of adding two positive numbers is a negative number. The cause of the error is overflow.

* The overflow detection mechanisms used mainly include the bitwise decision method and the two-symbol bit decision method.

(1) Dual-symbol bit determination method. If two symbols are used to represent the symbol, that is, 00 indicates the positive number and 11 indicates the negative number, the two symbols are inconsistent when the overflow occurs.

To determine whether an overflow exists.

If the two symbols of the calculation result are expressed as S1 and S2, the logic expression of the difference overflow is-VF = S2XORS1.

Set a positive integer X = + 10000001, Y = + 10000011. If the positive integer X = +,

Then X supplements 00 10000001; Y supplements 0010000011.

Result s2 and S1 are inconsistent, indicating overflow during the operation.

Verification Code

During computer system operation, data must be exchanged between various components to ensure that the data is correct during transmission.

The first is to improve the reliability of the hardware circuit, and the second is to improve the code verification capability, including error checking and Error Correction. Generally, the verification code is used.

The basic idea is to divide the possible data encoding into two types: Valid encoding and

Error code. Valid codes are used to transmit data. error codes are codes that are not allowed to appear in the data.

Encoding Rules make the data become an error code when an error occurs during transmission, so that you can detect whether the received data is

Error

Code margin: an important concept in a verification code. The so-called code margin refers to at least two valid codes in an encoding system.

The number of binary digits is different. For example, the length of the 4-digit 8421 code is 1. During transmission, one or more digits of the Code are incorrect.

, Both are half changed to another legal code, so this code has no error verification capability.

** Three verification Codes

1. parity code

Parity is a simple and effective verification method. This method adds a parity bit to the Encoding

The odd or even number of values of 1 is used to change the code distance to 2.

From table 1-7, we can see that the 8421 code of the parity bit consists of four information bits and one verification bits. The code distance is 2 and the code can be checked out.

An error occurs when the odd number of information is incorrect. The error cannot be checked, that is, it can only detect errors, but cannot correct errors.

* There are three common parity codes:

(1) Horizontal parity code. Add a check bit to encode each data so that the information bit and the check bit are in the same row.

(2) vertical parity code: This type of parity code divides data into several groups. A group of data occupies one row and is neatly arranged.

One line of verification code. Odd or even checks are used for each column.

1. Haiming code

Hamming code is also a verification method that uses parity to detect errors and correct errors,

Hamming Code Construction Method: insert K verification BITs between data to enable error detection and error correction by extending the code distance.

Related Keywords:
Related Article

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.