main( ){
char
c=
040
;
printf(“%o
\n",c<<
1
);
}
According to the above calculation rules, we first converted to binary 12, 1100, anti-bit-logic operations, compared with 0011, the result should be a decimal number into 3 fishes ah, why the test results -13 it?
The original ah, in the computer, storage is a binary code stored in the form of a supplement.
Therefore, stored in the computer 12 is 01100 (0 a first sign bit, representing the number is positive), subjected to inverse logical operation was 10,011, but this is only stored in the form of a binary variable b in the computer ( i.e. complement form b), so we need to convert the original code form, since the sign bit is 1, is negative, so we first converted to the inverted 10011, i.e., 11100, and then subjected to +1, so the result 11101 is converted to a decimal number, compared with -13. Therefore, b = -13.
Binary computer code print are complementary forms of
Positive original code, anti-code and complement three yards one
Negative original code is converted into complement sign bit constant value of the last one bit bitwise plus a
Negative, complement of the complement of the original code is equal to the inverted positive three yards one
(5) right shift operation rules: the left to fill the vacated bit with 0 or 1. 0 filled with positive, negative, filled with 1. Note: The way to fill the different environments may be different; the lower right overflow This bit is discarded.
a = 127, converted to binary to 01111111, since in binary is stored in the form of a computer inside the complement, but since 127 is positive, so its complement is 01111111, the complement arithmetic right shift operation, in accordance with the operation rules to give 00011111, is converted to the original code, still as 00011111, is converted to the decimal number 31, therefore, b = 31.
a = -127, is converted to binary 100001111111, is converted to the inverted 111,110,000,000, is converted into complement 111,110,000,001, three left shifts its operation to obtain: 110000001000, to convert is inverted: 110000000111, which is then converted into the original code: 101111111000, converted to decimal numbers, as -1016, so b = -1016.
A plurality of sets of test data, we can get a pattern:
new number when a number of n-bit left shift operation performed, the resulting operand is = * 2 ^ n.