1
1
123qwe2015-10-10 12:48:10
Programming
123qwe, 2015-10-10 12:48:10

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

3 answer(s)
A
Andrey Pavlenko, 2015-10-10
@Akdmeh

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.

T
Tlito, 2015-10-10
@tlito

https://en.wikipedia.org/wiki/%D0%94%D0%BE%D0%BF%D...

A
Anton Fedoryan, 2015-10-12
@AnnTHony

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 question

Ask a Question

731 491 924 answers to any question