Source code, anti-code, complement, and transfer code

Source: Internet
Author: User
Document directory
  • I. Definition of source code, reverse code, and complement code
  • Ii. Rules for code addition and subtraction
  • I. Floating Point calculation rules
I. Definition of source code, reverse code, and complement code

1. Definition of the original code

① Definition of decimal original code

 

[X]Original=

  X 0 ≤ x <1
  1-x -1 <x ≤ 0

Example: X = + 0.1011, [X] original = 01011
X =-0.1011 [X] original = 11011

② Definition of integer original code

 

[X]Original=

  X 0 ≤ X <2n
  2n-X -2n <X ≤ 0

2. Definition of supplemental code

① Definition of decimal Complement

 

[X]Supplement=

  X 0 ≤ X <1
  2 + X -1 ≤ X <0

Example: X = + 0.1011, [X] fill = 01011
X =-0.1011, [X] fill = 10101

② Integer complement Definition

 

[X]Supplement=

  X 0 ≤ X <2n
  2n + 1 + X -2n ≤ X <0

3. Anti-Code definition

① Decimal anticode Definition

 

[X]Reverse=

  X 0 ≤ X <1
  2-2 n-_x -1 <X ≤ 0

 

Example: X = + 0.1011 [X] inverse = 01011
X =-0.1011 [X] reversed = 10100

② Integer anticode Definition

 

[X]Reverse=

  X 0 ≤ X <2n
  2n + 1-_x -2n <X ≤ 0

4. Shift code: The Shift code is only used to represent the order code of the floating point number, so it is only used as an integer.

① Shift code definition: Set the order code consisting of 1-bit sign bits and n-bit numeric bits, then [X] shift = 2n + X-2n ≤ X ≤ 2n
Example: X = + 1011 [X] shift = 11011 sign bit "1" indicates the positive number
X =-1011 [X] shift = 00101 sign bit "0" indicates negative number

② Relationship between code transfer and CAPTCHA complement: [X] The Relationship Between the CAPTCHA shifting and [X] Is that the signed bits are opposite to each other,
Example: X = + 1011 [X] shift = 11011 [X] fill = 01011
X =-1011 [X] shift = 00101 [X] fill = 10101

③ Considerations for code transfer operations:
◎ The result of the bitwise operation needs to be corrected. The correction amount is 2n, that is, the result is the correct result of the bitwise inversion of the result.
◎ Indicates that 0 has a unique encoding: 1000... 00. When 000... 00 (-2n), which is a floating point.

Ii. Supplementary addition and subtraction operation rules 1. Operation Rules

[X + Y] fill = [X] fill + [Y] fill
[X-Y] fill = [X] fill + [-Y] fill

If the [Y] population is known, the [-Y] population method is to take the [Y] population (including the symbol bit) Bit by bit and then add 1 in the trim bit.
For example, [Y] fill = 101101 [-Y] fill = 010011

2. Overflow judgment. Generally, dual-symbol bit is used for judgment:

Symbol bit 00 indicates positive number 11 indicates negative number
When the result is 01, it is called overflow; when it is 10, it is called underflow.

Example: set x = 0.1101, y =-0.0111, And the symbol bit is double sign bit
Returns x + y and x-y by using the complement code.
[X] fill + [y] fill = 00 1101 + 11 1001 = 00 0110
[X-y] fill = [x] fill + [-y] fill = 00 1101 + 00 0111 = 01 0100
Incorrect result. Positive overflow 3. Implementation of the first-digit multiplication of the original code:

Set X = 0.1101, Y =-0. 1011, and calculate X * Y.
Solution: The symbol bit is processed separately, x + y
The value part uses the original code for a multiplication, as shown in:

  High part product Low part product/Multiplier Description
  0 0 0 0 0 0 1 0 1 1     Start Condition
+) 0 0 1 1 0 1     The multiplier is 1, + X
       
  0 0 1 1 0 1      
  0 0 0 1 1 0 1 1 0 1 1 (lost) Right shift partial area and multiplier
  +) 0 0 1 1 0 1     The multiplier is 1, + X
       
  0 1 0 0 1 1      
  0 0 1 0 0 1 1 1 1 0 1 (lost) Right shift partial area and multiplier
  +) 0 0 0 0 0 0     The multiplier percentile is 0, + 0
       
  0 0 1 0 0 1      
  0 0 0 1 0 0 1 1 1 1 0 (lost) Right shift partial area and multiplier
  +) 0 0 1 1 0 1     The multiplier is 1, + x
       
  0 1 0 0 0 1      
  0 0 1 0 0 0 1 1 1 1 1 (lost) Right shift partial area and multiplier
         

4. Implementation of one-digit division of the original code: do not restore the remainder (addition and subtraction alternate method)

  Partial product Additional bit of the low part product Operation instructions
  0 0 0 0 0 0 1 0 1 1     Start Condition
+) 0 0 0 0 0 0     The multiplier is 1, + x
       
  0 0 0 0 0 0      
  0 0 0 0 0 0 1 1 0 1 1 (lost) Right shift partial area and multiplier
  +) 1 1 0 0 1 1     The multiplier is 1, + X
       
  0 1 0 0 1 1      
  0 0 1 0 0 1 1 1 1 0 1 (lost) Right shift partial area and multiplier
  +) 0 0 0 0 0 0     The multiplier percentile is 0, + 0
       
  0 0 1 0 0 1      
  0 0 0 1 0 0 1 1 1 1 0 (lost) Right shift partial area and multiplier
  +) 0 0 1 1 0 1     The multiplier is 1, + X
       
  0 1 0 0 0 1      
  0 0 1 0 0 0 1 1 1 1 1 (lost) Right shift partial area and multiplier

§ 2. 5 floating point operations and floating point Calculator

I. Floating Point calculation rules 1. Operation steps of floating point addition and subtraction

Set two floating point numbers X = Mx ※2ex Y = My ※2ey
To implement X ± Y, follow these steps:
① Level-1 operation: the level-1 operation is aligned with the level-1 operation.
② Perform addition and subtraction of the number of tails
③ Normalized processing: The result of the operation on the tail number must be a normalized floating point number. For the complement tail number of the double sign bit, it must be
001 ×××... ×× Or 110 ×××... ×× Format
If the Left or Right rules are not met.

④ Rounding operation: When performing the order or right rule operation, you can use the "0" and "1" to round the number of tails that have been removed right to ensure accuracy.
⑤ Correctness of the judgment result: Check whether the level code overflows
If the level code overflows (the shift code indicates that it is 00... 0), set the result to machine 0;
If the level code overflow (exceeds the maximum value indicated by the level code), the overflow flag is set.

Example: Suppose X = 0. 0110011*211, Y = 0.1101101*2-10 (the numbers here are both binary )?? Calculate X + Y;
Solution: [X] float: 0 1 010 1100110
[Y] floating: 0 0 110 1101101
Tail Number of the signed level code

Step 1: Calculate the order difference: │ △e │ = | 1010-0110 | = 0100
Step 2: lower order: the order code of Y is small, and the tail number of Y shifts four places to the right.
[Y] float changes to 0 1 010 0000110 1101 temporarily saved
Step 3: add the ending number and use the double sign bit complement operation
00 1100110
+ 00 0000110
00 1101100
Step 4 Normalization: Meet normalization requirements
Step 5: Use the 0 homes and 1 homes Method for rounding
Therefore, the floating point number format of the final calculation result is 0 1 010 1101101,
That is, X + Y = + 0. 1101101*210

2. Operation steps of floating-point multiplication and division

① Order code operation: sum (multiplication) or difference (Division) of Order code)
That is, [Ex + Ey] shift = [Ex] SHIFT + [Ey] fill
[Ex-Ey] shift = [Ex] SHIFT + [-Ey] fill

② Floating point ending number processing: The result of the floating point number multiplication and division operation must be rounded.
Example: x = 0. 0110011*211, y = 0.1101101*2-10
X ※y
Solution: [x] float: 0 1 010 1100110
[Y] floating: 0 0 110 1101101
Step 1: Add Order Codes
[Ex + ey] shift = [Ex] SHIFT + [ey] fill = 1 010 + 1 110 = 1 000
1 000 is the value 0 indicated by the transfer code
Step 2: the result of multiplying the ending number of the original code is:
0 10101101101110
Step 3: normalization: the specifications have been met, and no left gauge is required. The number of tails remains unchanged and the order code remains unchanged.
Step 4: Rounding: Follow the Rounding Rule and Add 1 to correct
So X ※y = 0.1010111 ※2 + 000

 

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.