Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Conversion between unsigned number and signed number
Conversion between unsigned number and signed number
Conversion between signed and unsigned numbers in languages;

Unsigned number: There is no difference between positive and negative, and all bits are used to represent the number itself.

Signed number: the highest bit is used to indicate positive or negative numbers, the highest bit is 1, indicating negative numbers, and the highest bit is 0, indicating positive numbers.

1. Conversion from unsigned number to signed number: see whether the highest digit of unsigned number is 1, and if it is not 1 (i.e. 0), the signed number is directly equal to the unsigned number;

2. If the highest bit of the unsigned number is 1, take the complement of the unsigned number, and the obtained number is the signed number.

3. Convert signed number into unsigned number: See if the highest digit of signed number is 1. If it is not 1 (that is, 0), the unsigned number is directly equal to the signed number;

4. If the highest bit of the signed number is 1, take the complement of the signed number, and the obtained number is the unsigned number.

1. Signed numbers are binary. Most significant bit is used as the sign bit, where "0" stands for "+"and "1"stands for "-"; The remaining digits are used as digits to represent numerical values.

2. Representation of signed numbers: The data in the computer is represented by binary, and the symbol of numbers can only be represented by 0/ 1. Generally, most significant bit (MSB) is used to represent the sign of numbers, positive numbers are represented by 0, and negative numbers are represented by 1.

3. Symbolic coding methods, commonly used are complement, in addition to the original code and anti-code. When using different binary coding methods to represent signed numbers, the number of machines obtained may be different, but the truth value is the same.

References:

Baidu Encyclopedia _ Signing Number