Chapter One: number systems and codes

Source: Internet
Author: User
Tags modulus

Number system

First, the decimal

The rounding rule is " every ten in one ." A decimal of any n-bit integer and M-decimal can be expressed as:


which

Ki-is called the coefficient of the number of numbers, representing the factor of the I-bit, the value of decimal ki is 0 ~ 90 number, I take the value from (n-1) ~0 all positive integers to -1~-m all negative integers

10i-represents the weighted value of the position I, 10 is the base, that is, the number of digital

N, M is a positive integer, n is the number of digits of the integer part, and M is the number of decimal parts.

For example

(249.56) 10=2x102+ 4x101+ 9x100+ 5x10–1+ 2x10-2

Ii. binary

The rounding rule is "every binary one", and any n-bit integer, M-decimal binary can be represented as

which

ki-value only two digital: 0 and 1

2i-is a binary right with a base of 2

N, M is a positive integer

such as (11011.101) 2=1x24 +1x23 +0x22 +1x21 +1x20 +1x2-1+0x2-2 +1x2-3= (27.625) 10

Three or eight binary

The rounding rule is "every eight in one" and its base is 8. Any n-bit integer, octet of M decimal, can be represented as

which

ki-value of 8 digital: 0~7

8i-is the right to octal, with a base of 8

N, M is a positive integer

such as (13.74) 8=1x81+3x80 +7x8-1+4x8-2 = (11.9375) 10

46 or 16 binary

The rounding rule is "every 16 in one" and its base is 16. Any one n-bit integer, M-decimal hexadecimal can be represented as

which

ki-values are 16 digital: 0~9, A (10), B (11), C (12), D (13), E (14), F (15)

The right to 16, with a base of 16

N, M is a positive integer

(f9.1a) 16=15x161+9x160 +1x16-1+10x16-2 = (249.1015625) 10

A digital binary representation that can be subscript, such as (n) 2 for binary, (n) 10 for Decimal, (n) 8 for octal, (n) 16 for hexadecimal

Sometimes the subscript is also denoted by letters, such as (n) B for binary, b-binary, (n) D for Decimal, D-decimal, (n) O for octal, O-octal, (n) H for hexadecimal, h-hexadecimal;

The following table shows the different binary representations of 0~15 digital

D

B

O

H

D

B

O

H

0

0000

00

0

8

1000

10

8

1

0001

01

1

9

1001

11

9

2

0010

02

2

10

1010

12

A

3

0011

03

3

11

1011

13

B

4

0100

04

4

12

1100

14

C

5

0101

05

5

13

1101

15

D

6

0110

06

6

14

1110

16

E

7

0111

07

7

15

1111

17

F

Conversion between the different numbering

System conversion: Conversion between different digital conversions is called a conversion

One or two binary number, octal number and hexadecimal number converted to decimal number

The binary, octal, and hexadecimal numbers are converted to decimal numbers by expanding the binary, octal, and hexadecimal numbers by the following formula

For example:

Second, the decimal number is converted into binary number:

The decimal number is converted to binary number, the principle is "integer except 2, decimal by 2

A. Integer conversions in decimal:

The integer portion of the decimal is removed with the Radix 2, the remainder is retained, and then the quotient is in addition to 2, in turn, until the quotient is 0, and the remaining number is the integer part of the corresponding binary number.

B. Decimal conversion of decimals

The decimal number is multiplied by the Radix 2, the whole number of the product is preserved, and then the fraction of the product continues to multiply by 2, and then goes down until the product is 0 or reaches the required precision, and the integral part of the product is the fractional portion of the corresponding binary number.

Example converts (173.39) d to a binary number, which requires an accuracy of 1%

Solution: The process is as follows

A. Integral parts

i.e. (173) d= (10101101) B

B. Number of sub-parts

Because of the accuracy requirement of 1%, it should make the logarithm of 2-m≤1% to get 2-m≤10-2; 2m≥100;mlg102≥lg10100;m≥6.6

Take m=7 to meet the accuracy requirements, the process is as follows

i.e. (0.39) d= (0.0110001) B

therefore (173.39) d= (10101101.0110001) B

And so on, for the decimal conversion to other binary, as long as the base 2 into other binary cardinality.

Three or two binary conversion to octal and hex

Method: Because 3-bit binary number can have 8 states, 000~111, exactly 8, and 4-bit binary number can have 16 states, 0000~1111, exactly 16, so you can group binary numbers. Octal three-bit is divided into a group, not enough to fill 0, hexadecimal four-bit into a group.

Note: If the octal or 16 binary is converted to binary, the binary number is expanded by three-bit or four-bit.

Reminder: To convert decimal to octal or 16, you can convert to binary, then group, and convert to octal or hex.

Arithmetic operations of the binary

Characteristics of binary arithmetic operations

When two binary digits represent a size of two numbers, and these two numbers are numerically operated, this operation is called arithmetic. Its rule is "every two in one", "borrow one when two". Arithmetic operations include "subtraction", but the minus, multiply, and divide can eventually be converted to signed addition operations.

Arithmetic operations such as two numbers 1001 and 0101 are as follows

    

Anti-code, complement, and complement operations

First, the original code:

When using binary digital to represent a value, how is the positive or negative difference? Binary number of the positive and negative value of the expression is in the binary digital before adding a sign bit, with "0" for positive numbers, "1" for negative numbers, this signed bit of binary digital is called the original code.

For example: +17 The original code is 010001,-17 the original code is 110001

Second, anti-code

The inverse code is to not do the subtraction when the complement is obtained. Binary Anti-code method is: positive inverse code and the original code is the same, negative number of the original code in addition to the symbolic bit of the value part of the reverse, that is, "1" changed to "0", "0" to "0".

For example +7 and-7 of the original code and complement are:

+7 The original code is 0 111, the inverse code is 0 111

-7 of the original code is 1 111, the inverse code is 1 000

Note: 0 of the anti-code has two representations, +0 of the anti-code is 0 000,-0 of the anti-code of 1 111

Three, complement:

As a binary subtraction, you can use the complement to convert the subtraction operation into an addition operation. Introduce the concept of modulo (or modulus) prior to the complement

1. The concept of modulus (modulus):

The length of the cycle of a thing, called the modulus or modulus of the event.

such as 365 days a year, its modulus is 365; clocks are counted in 12 for a cycle, so modulus is 12. The decimal count is 10 digital 0~9, the cycle, so the modulus is 10.

Take the table as an example to introduce the principle of complement operation: for the clock shown in the picture

When you find that the table stops at 10 o ' 5 o'clock, there are two ways to dial back:

A. Counter-clockwise dial 5, that is 10-5=5, which is to do subtraction.

B. Dial seven clockwise, that is, 10+7=17, because the modulus is 12, so 1 is equivalent to carry 12,1 overflow, it is 7 lattice, is also 17-12=5, which is to do the addition.

This shows that the effect of 10+7 and 10-5 is the same, and 5+7=12, so 7 is called-5 of the complement, that is, complement, can also be said that subtraction can be replaced by the complement of the addition.

2. the expression of complement

The complement of the positive number is the same as the original code, the complement of the negative is the sign bit "1", the value bit is reversed plus "1", namely "anti-code plus 1".

Example: Original code anti-code complement

+7 0 111 0 111 0 111

-7 1 111 1 000 1 001

Attention:

1. With the complement, the subtraction operation can be easily converted into addition operations, and multiplication and division can be achieved by shifting and adding, so that the computational circuit structure can be simplified;

2. A positive complement is the true value of the number it represents, and the complement of the negative is not the true value of the number it shows.

3. Different from the original code and the inverse code, "0" the complement only one, namely (00000000) B

4. Known source code, complement and anti-code: Positive number of the original code and complement, anti-code the same; negative inverse code is the symbol bit unchanged, the value is reversed, and the complement is the sign bit unchanged, the value of the inverse plus "1".

such as: The original code is 10110100, its anti-code is 11001011, the complement is 1100100.

5. Know the complement, seek the original code: positive complement and the original code is the same; the complement of the negative number should be the value of "1" and then reverse, but for the binary number, the first minus "1" to reverse and first take the reverse and add "1" The result is the same. Therefore, the complement of the negative number to seek the original code is the value of the inverse plus "1".

If it is known that the complement of a number is (11101110) b, its original code is (10010010) b

6. If the number of bits in the binary is N, the number of signed digits that can be represented is ( -2n~ 2n-1-1), such as n=8, can be represented ( -128~127), so when doing the addition, note that the absolute value of two numbers does not exceed the range of the number that it represents.

4-bit binary code with symbol bit, inverse code and complement table

Decimal number

Original code

Anti-code

Complement

Decimal number

Original code

Anti-code

Complement

+7

0111

0111

0111

-1

1001

1110

1111

+6

0110

0110

0110

-2

1010

1101

1110

+5

0101

0101

0101

-3

1011

1100

1101

+4

0100

0100

0100

-4

1100

1011

1100

+3

0011

0011

0011

-5

1101

1010

1011

+2

0010

0010

0010

-6

1110

1001

1010

+1

0001

0001

0001

-7

1111

1000

1001

0

0000

0000

0000

-8

1000

1111

1000

Binary encoding

Three terms

Digital : Represents an exact number, such as binary number, octal number, and so on.

code : A specific binary digital group, is a different signal code, not necessarily have a number of meanings.

encoding : n-bit binary number can be combined into 2n different information, to each information set a specific code group, this process is called coding. There are two kinds of coding commonly used in digital system, one is binary encoding and the other is two-decimal code. In addition, regardless of the binary code or two-decimal code, can be divided into the right code (each digital representative of the fixed weight) and unauthorized code.

Decimal code

Use 4-bit binary code to represent decimal 0~9 digits, which is the two-decimal encoding. 4-bit binary code can have 0000~1111 16 states, it means that 0~9 10 states can have a variety of coding forms, which are commonly used to have 8421 yards, 3 yards, 2421 yards, 5211 yards, more than 3 cycle codes, including 8421 yards, 2421 yards, 5211 yards for the right code, That is, each bit of 1 represents a fixed value.

Several coding forms

Description

1.8421 yards: Also known as BCD Code, is the most commonly used decimal code. The right of each person is 8, 4, 2, 1, such as (0101) 2=1x4+1x1=5

2. The remaining 3 yards is not a power code, because it is expanded by the binary decimal number than the corresponding decimal number is greater than 3. If 0101 means 2, and its expansion decimal number is 5, it is called the remainder 3 yards. The advantage of using more than 3 yards is: using the remainder 3 yards to do the addition, if the resulting sum of 10, exactly corresponding to the binary 16, can automatically generate a carry signal. such as 0110 (3) +1010 (7) =1111 (10), and 0 and 9, 1 and 8, 2 and 7 ... is the reciprocal code, which is very convenient for the complement.

3.2421 yards is the right code, each of its rights is 2, 4, 2, 1, such as (1100) 2=1x2+1x4=6, with the remainder 3 yards the same 0 and 9, 1 and 8, 2 and 7 ... is the inverse of each other code. In addition, when any two of these coded values are added equal to 9 o'clock, the result of the 4 binary codes must be 1111.

4.5211 yards is also the right code, each of its rights is 5, 2, 1, 1, such as (0111) 2=1x2+1x1+1x1=4, mainly used in the divider.

5. More than 3 loop code is not authorized code, it is characterized by the adjacent two code between only one state is different. This is not an error in decoding (competition-adventure)

Binary code:

It includes natural code and cyclic code (gray code)

Natural code: The right code, each code has a fixed weight, the structure of the form and the binary number is exactly the same, the maximum count is 2n-1,n for the number of digits of the binary number.

Cyclic code: Also known as Gray Code, it is not authorized code, each code has no fixed weight, its composition is the lowest bit of gray code is 0110 cycles, the second is 00111100 cycles, the third is 0000111111110000 loops, and so on can get multi-digit gray code. Gray code is characterized by any adjacent two code group, only one code is different, strong anti-jamming ability, mainly used in the counter.

Chapter One: number systems and codes

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.