Answer the question
In order to leave comments, you need to log in
Why is there a minus in bit shifts?
Here is the code:
int a=-7;
a<<=1;
a>>=1;
printf("%d\n",a);
10000111
00001110
00000111
Answer the question
In order to leave comments, you need to log in
if I understand correctly, the sign is stored in the first bit
The additional code allows you to replace the subtraction operation with the addition operation and make the addition and subtraction operations the same for signed and unsigned numbers, which simplifies the computer architecture.
The binary representation is -7 actually 11111001 * **
*if you don't take exotic architectures into account
**assuming that int suddenly became single byte
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question