[Soft test test site analysis] Software designer-original code, inverse code, complement code

1. Title

If the complement of 2X is 90H, the true value of X is:
A 72
B -56
C 56
D 111

2. Theory

This involves the theory of original code, inverted code, and complement code. This is actually very simple. Remember to score, but if you can’t remember, you can basically rely on blindness. Because the probability of passing the test is very high, I suggest that everyone remember it.

The number of machines (the form of data saved in the computer) is binary, divided into unsigned numbers and signed numbers. The highest bit of the signed number represents the sign bit, and the encoding method of original code, inverted code, and complement code can be used.

2.1 Original code

The highest bit is the sign bit, 0 means positive number, 1 means negative number, and the other part is the absolute value of the number. For example:
0000 0001express 1, 1000 0001express -1.

2.2 Inverse code

The highest bit is the sign bit, 0 means positive number, 1 means negative number. When the sign bit is 0, the other part is the absolute value of the number; when the sign bit is 1, the remaining part needs to be inverted bit by bit . For example:
0000 00001indicates that 1it 1000 0001needs to be reversed bitwise 1111 1110, so it indicates -126.

2.3 Complement

The highest bit is the sign bit, 0 means positive number, 1 means negative number. When the sign bit is 0, the other part is the absolute value of the number; when the sign bit is 1, the remaining part needs to be inverted bit by bit and then 1 is added . For example:
0000 00001means that 1it 1000 0001needs to be reversed bitwise 1111 1110, and then add 1 to 11111111, so it means -127.

3. Analysis

Look at the title, the complement of 90H is 1001 0000, so it is a negative number, and the value is bitwise inverted 1101111, plus 1 to 1110000, which is 112.
So 2X=-112, X=-56, choose B.

Guess you like

Origin blog.csdn.net/woshisangsang/article/details/108554838