[On the road to the soft exam] - original code, inverse code, complementary code, shift code

Copyright: This is an original post by the blogger and may not be reproduced without the blogger's permission. https://blog.csdn.net/huyuyang6688/article/details/45267563

The representation of various numerical values in a computer is called machine number, which uses binary numbers to represent data, and the positive and negative signs of the data are also represented by 0 and 1, respectively. To facilitate arithmetic, machine numbers with symbols can be encoded using original code, inverse code, complementary code, shift code, and other encoding methods.

Note: The following rules are all based on machine character length is 8 (i.e., 8 binary bits are used to represent the data) to give an example.

⊙ positive numbers: as follows ① first write the data to be represented, ② write 0 in the sign bit (first bit), ③ fill in with 0 if there is an empty space, e.g. X = 22 = 10110B, then [X] originally = 00010110.

⊙ negative numbers: as follows ① first write the data to be represented, ② write 1 in the first place, ③ if there are empty spaces then fill them with 0, e.g. X = -27 = -11011B, then [X] originally = 10011011.

⊙ positive: the inverse is equal to the original, e.g. X = 10110, then [X]inverse = [X]original = 00010110.

⊙ Negative numbers: as follows, based on the original code, ④ the sign bit (first bit) remains unchanged, ⑤ the other bits are inverted by bit (0 becomes 1,1 becomes 0), e.g. X = -11011, then [X] original = 10011011, [X] inverse = 11100100.

⊙positive number：binary code with 0 and 1 interchanged tantamount to original code harmony inverse code， as ifX=10110， follow[X] patch=[X] contrary=[X] primary=00010110；

⊙ Negative: on top of the inverse code, (6) let the inverse code add 1. For example, if X = -11011, then [X] original = 10011011, [X] inverse = 11100100, [X] complement = 11101101.

Both positive and negative shifts are based on the inverse code by letting the sign bit of the inverse code be inverted, which gives the shift code for that number. If X=-11011, then [X]original=10011011, [X]inverse=11100100, [X]complement=11100101, and [X]shift=01100101.

The conversion between the representations of original code, inverse code, complement code, and shift code is basically only a little different when converting positive and negative numbers, and when it comes to decimals, you just need to represent the decimals as binary as well, and convert them in the same way as positive numbers. If X = 0.25 = 0.01, [X]original = 0.0100000, [X]inverse = 0.1011111, [X]complement = 0.1100000, and [X]shift = 1.1100000.