Answer the question
In order to leave comments, you need to log in
How to represent a negative number in binary?
What's up, software.
Take for example 7.
int a = 7; (4 bytes)
7 would look like this - 00000000 00000000 00000000 00000111.
-7 would look like this - 00000000 00000000 10000000 00000111. Yes? not sure.
If I'm right, is it that simple, or are there some tricks with some numbers?
Give a couple of examples, pliiz. I'm trying to deal with the fundamentals.
Answer the question
In order to leave comments, you need to log in
Lots of subtleties. In a nutshell - it all depends on the device you are using.
https://ru.wikipedia.org/wiki/%D0%94%D0%B2%D0%BE%D...
inf1.info/additionalcode
Here are two articles on the subject.
If you use the calculator in the "programmer" mode, the result will be:
+7: 00000000 00000111
-7: 11111111 11111001
I.e. we take the original number modulo, invert all bits and add one.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question