Get the App
SLTechnology News&Howtos  ›  Servers  › 

The original code, complement code and inverse code of the algorithm (4)

Shulou Source: shulou.com Published: 2022-06-03 03:55:52 10月03日 Update

[1] Original code, complement code and complement code are the coding methods for storing a specific number by the machine.

original code

[2] The original code is the absolute value of the sign bit + the true value, the first bit represents the sign bit, and the remaining bits represent the value.

For example:

An 8-bit binary

0000 0001 (1 original code)

1000 0001 (-1 original code)

8-bit binary representation range is

1111 1111-0111 1111(-127,127)

complement

The complement of a positive number is itself, and the complement of a negative number is based on its original code, with the sign bit unchanged and the rest inverted.

that is

0000 0001 (1 original code)---The complement is the same 0000 0001 (1 complement)

1000 0001 (-1 original code)---inverted code symbol bit unchanged, the rest of the inverted 1111 1110 (-1 inverted code), this number can not see what is represented, need to be converted to the original code to see.

complement

The complement of a positive number or itself,

The complement of a negative number is based on the original code, or the complement of the final +1.

[Summary]

Positive--complement (self)--complement (self)

Negative--complement (sign bit unchanged, rest inverted)--complement (complement +1)

[Example: ]

byte b = (byte) 130;

b = ?

[Analysis]

1. All operations in the computer are complementary.

2, calculate the binary data, 130 (default int type 4 bytes), that is, 1000010 (1 byte)

4-bit byte complement is:

000000 0000000 0000000 1000010 (positive-negative-original)

byte Truncate a byte, i.e.(1000010)---(complement)

3, complement to complement code 1000001

4. Reverse code to original code 1 111110 (-126)

[Expansion]

Here we analyze

byte b = (byte) 130;

b = -126;(byte-128: artificially specified-0 is-128----127)

Which means it's a loop, which means

127(127)

128 (-128)

129(-127)

130(-126)

131(-125)

.....

400(-112)

Calculation idea:

From-128--127 to 256

400-256=144(-112)

Tags: Inverse codes complements symbols bytes positive numbers that is binary negative numbers that is the basis is in analysis the same number that is ideas numbers data methods machines Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Linux Apple Docker Shulou Information