Linked Questions
20 questions linked to/from Why prefer two's complement over sign-and-magnitude for signed numbers?
-4 votes
1 answer
1k views
Why "-1" is 11111111 not 10000001 in signed int [duplicate]
I'm doubt why we uses -1 as 11111111 in signed int, not 10000001. because as we learned first bit is use to specify the sign and rest of the seven bits are for the value. So in what reason designers ...
1 vote
0 answers
39 views
Bit in the +/- form [duplicate]
I recently wondered about why not just use one bit as "+/-" and use the other as a number module? Will their use not be rational or are there some other factors that prevent this from being ...
522 votes
24 answers
503k views
What is “two's complement”?
I'm in a computer systems course and have been struggling, in part, with two's complement. I want to understand it, but everything I've read hasn't brought the picture together for me. I've read the ...
94 votes
11 answers
88k views
How are integers internally represented at the bit level in Java?
I am trying to understand how Java stores integers internally. I know all Java primitive integers are signed, (except short?). That means one less bit available in a byte for the number. My question ...
31 votes
3 answers
23k views
Why are signed and unsigned multiplication different instructions on x86(-64)?
I thought the whole point of 2's complement was that operations could be implemented the same way for signed and unsigned numbers. Wikipedia even specifically lists multiply as one of the operations ...
18 votes
6 answers
14k views
Why Two's Complement?
I'm writing a tutorial to teach kids (ages 9 to 13) about programming. I started with computers themselves, they don't have that much to do with computer science, it's more about the process involved ...
6 votes
6 answers
13k views
Bits representation of negative numbers
This is a doubt regarding the representation of bits of signed integers. For example, when you want to represent -1, it is equivalent to 2's complement of (+1). So -1 is represented as 0xFFFFFFF. Now ...
20 votes
2 answers
2k views
What is the meaning of "producing negative zeroes" in a system that doesn't support it?
C17 6.2.6.2/4 says: If the implementation does not support negative zeros, the behavior of the &, |, ^, ~, <<, and >> operators with operands that would produce such a value is undefined....
13 votes
2 answers
3k views
How does Java calculate negative numbers?
I use the ~ operation for bit manipulation, and I'm just wondering how Java calculates the negative number? I checked the Java documentation: "The unary bitwise complement operator "~" inverts a ...
5 votes
4 answers
3k views
Why Do We have unsigned and signed int type in C?
I am a beginner in C . I have recently learned about 2's Complement and other ways to represent negative number and why 2's complement was the most appropriate one. What i want to ask is for example, ...
7 votes
5 answers
4k views
Where did the leading 1 means negative number in signed int arise from?
Even though I read a number of articles that say that mostly 2's complement is used to represent the negative numbers in a signed integer and that that is the best method, However for some reason I ...
4 votes
1 answer
10k views
Whats the highest and the lowest integer for representing signed numbers in two's complement in 5 bits?
I understand how binary works and I can calculate binary to decimal, but I'm lost around signed numbers. I have found a calculator that does the conversion. But I'm not sure how to find the maximum ...
1 vote
2 answers
5k views
Subtracting 1 from 0 in 8 bit binary
I have 8 bit int zero = 0b00000000; and 8 bit int one = 0b00000001; according to binary arithmetic rule, 0 - 1 = 1 (borrow 1 from next significant bit). So if I have: int s = zero - one; s = -1; -...
3 votes
3 answers
2k views
Why is binary subtraction always (?) done by adding the complement?
I'm looking for a good explanation why (not how, I know that) binary subtraction is always (?) done by adding the complement etc. Is it just because of the extra logic gates that would be necessary or ...
3 votes
2 answers
1k views
Is 2s complement a way to store negative number?
I have read many articles and SO answers to understand 2s complement. They have helped me a lot. However, there are few doubts in my mind about 2s complement. 1) Is 2s complement a way to store ...