is ~7 and 2's complement of 7 same in binary or do we have any relation among it. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

is ~7 and 2's complement of 7 same in binary or do we have any relation among it.

7th Dec 2017, 12:29 PM
Hema Chander
Hema Chander - avatar
3 Answers
+ 3
I'm sorry I misspoke. An integer number in most computers usually consists of a sign bit and some stuff after. For example the number 7, stored in an 8-bit char: 0 0000111 // 7 The one's complement, ~7, is obtained by flipping every bit: 1 1111000 // ~7 Almost all computers use two's complement integers though. So if you want to make a number negative, you take one's complement and add 1. 1 1111001 // ~7 + 1 == -7
7th Dec 2017, 12:52 PM
Schindlabua
Schindlabua - avatar
+ 2
And by the way, computers don't use one's complement for negative numbers because then the number 0 (binary 0 0000000) and ~0 == -0 (binary 1 1111111) would be different, but clearly 0 and -0 are the same number.
7th Dec 2017, 12:53 PM
Schindlabua
Schindlabua - avatar
0
need more explanation
7th Dec 2017, 12:45 PM
Hema Chander
Hema Chander - avatar