Answer the question
In order to leave comments, you need to log in
How to convert decimal negative number to binary?
How to implement it?
Everything is clear with positive ones, but I don’t know what to do with negative ones.
I could only get the reverse code of the number, but the last step, addition 1, led me to a dead end.
I saw implementations in PASCAL and C, I need in JAVA
Answer the question
In order to leave comments, you need to log in
Given: -128
1. Make a negative number positive
-128 => 128 (10000000)
2. Negate all bits
128 (10000000) => 127 (01111111)
3. Add 1 to the resulting number
127 (01111111) => -128 (10000000 )
and what is there? you invert all bits and you add unit to this number. this is how "two compliment" works
I did not quite understand the question, because the solution itself is contained in it.
I will make an assumption that it is not clear - why is one added to the inverted value?
Need to write. What exactly is the problem is not clear.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question