0
Why is ~4 -3?
Can someone explain me why it works this way? If I flip all the bits, It seems like I would get a very big number. My questions are: 1. What is 1's and 2's complement? 2. How does the computer know which one is used? 3. Does the amount of bits give me another answer of ~4 (or any other number)?
13 RĂ©ponses
+ 8
take a look at this lesson
and the code
the key to your answer lies in how numbers are represented by a computer and what is the MSB (research it ;) )
https://www.sololearn.com/learn/4076/?ref=app
https://code.sololearn.com/WBOdrCZZT0a7/?ref=app
+ 6
nope
the left most bit (MSB) determines the sign of the number (1 for negative, 0 for positive)
and numbers with a minus sign numbers it works the opposite (almost)
-1 for example is a composed of only 1's
-1
1111 1111 1111 1111 1111 1111 1111 1111
-2
1111 1111 1111 1111 1111 1111 1111 1110
-3
1111 1111 1111 1111 1111 1111 1111 1101
and so on
+ 2
Look into twos complement if you want to know more
+ 1
Lucas Knook you are correct. All modern processors use twos complement, it hardwired in their ALU. Only legacy systems use ones complement. See this for more info https://superuser.com/questions/1137182/is-there-any-existing-cpu-implementation-which-uses-ones-complement
0
yes, I have seen these, and I understand what MSB means, but still, I don't understand.
0
when I put in 5, I get this as result:
1111Â 1111Â 1111Â 1111Â 1111Â 1111Â 1111Â 1010
Shouldn't this be a very big number?
0
Am I correct if I say when the msb is 1, and the number is negative, I have to look for the zero's instead of the one's and then substract 1 from what I get? Also, how does the computer know it uses one's complement or two's complement? Or can a computer only use one of them?
0
I know complementing 0 and 1 is its opposite. 1 become 0 and 0 become 1.
0
So, I can say that when I use bitwise not, it flips all the ones and zero's including the MSB, which tells the computer that it is a negative number and then it reads 0 and 1 the opposite. after that it substracts one.
0
Yeah
0
I only have a little question left. Why does it substract one? can't 1111 1111 just be zero?
0
Cause then you have two zeros
0000 0000 and
1111 1111
0
ah, that makes sense. I understand now, thanks!