Algorithm of the original code, complement, anti-code (four)

[1] the original code, complement, anti-code is stored in a machine-specific digital encoding.

Original code

[2] the absolute value of the original code is the true value + sign bit, the first bit represents the sign bit, the remaining bits representative value.
For example:
an 8-bit binary
0000 0001 (the original code 1)
1000 0001 (-1 original code)
8-bit binary representation of the range
11111111-0111 1111 (-127,127)

Inverted

Positive anti-code per se, of the inverted negative which is based on the original code, the sign bit inverted remaining unchanged.
That
0000 0001 (original code 1) 0000 0001 ---- trans same code (Code 1 trans)
1000 0001 (-1 original code) ---- inverted sign bit inverted 11111110 remaining unchanged (-1 inverted), this number can not see what is represented by the need to turn to the original code to look out.

Complement

Positive or complement itself,
negative complement is based on the original code, anti-code or last +1.

[Summary]
positive - inverted (self) - complement (itself)
negative - inverted (sign bit unchanged, the remaining inverted) - complement (inverted +1)
[Example:]
byte b = (byte) 130;
? B =
[analysis]
1, the operational computer code is the complement of
a binary 2, calculation data, 130 (default type int 4 bytes), i.e., 1000010 (1 byte)
after up to 4 bytes:
00000000 00000000 1000010 (positive - trans code - the original code)
byte taken i.e. one byte (1000010) --- (complement)
3, anti-rotation complement code 10000001
4 trans ASCII to the original code 11111110 (-126)
[Development]
here we analyze
byte B = (byte) 130.;
B = -126; (128-byte: -128 ----- is an artifact -0 127)
i.e. said one cycle, that is
127 (127)
128 (-128)
129 (-127)
130 (-126)
131 (-125)
.....
400 (-112)
calculated idea:
from -128-- 127 256 total number of
400-256 = 144 (-112)

Guess you like

Origin blog.51cto.com/13479739/2412504