Linked Questions
131 questions linked to/from What is “two's complement”?
16
votes
7
answers
2k
views
Why does negating a value change the result when XORing it with 1? [duplicate]
I know the working of XOR,
Console.WriteLine(1^1); // returns 0
results to
00000001
00000001
--------
00000000
but how does this return 2?
Console.WriteLine(-(-1^1)); // returns 2
-2
votes
3
answers
5k
views
what is the value of all 32 bits set to 1 in int? [duplicate]
I was experimenting with bit operations in java
I tried setting bit index by index and this is what I have got.
Started setting with 0 th bit in the integer 0 to 31st bit (as int has got 32 bits ...
-1
votes
1
answer
7k
views
What is a two's complement Integer? [duplicate]
Java Datatypes like int,short,byte are two's complement integers ,as they menioned it in here . what information does it give when someone says that in java , int ,short or byte are two's complement ...
M Alok's user avatar
- 1,143
1
vote
3
answers
2k
views
Why Integer.MIN_VALUE is -2^32 while Integer.MAX_VALUE is 2^31-1? [duplicate]
I see in the JDK that Integer.MIN_VALUE is 0x80000000. Considering that the original is 0x80000000, then the opposite is 0x8fffffff, and finally the complement is 0x8fffffff + (-1) = -2^32? So whether ...
-1
votes
2
answers
3k
views
Java long byte length [duplicate]
If Java's long primitive data type is a 64-bit signed integer, then why do the Java docs state that the static long maximum value is 2^63-1? Is there a larger reason that affects other primitive data ...
4
votes
1
answer
2k
views
Why is absolute value of INT_MIN different from INT MAX? [duplicate]
I'm trying to understand why INT_MIN is equal to -2^31 - 1 and not just -2^31.
My understanding is that an int is 4 bytes = 32 bits. Of these 32 bits, I assume 1 bit is used for the +/- sign, leaving ...
0
votes
1
answer
5k
views
2's complement in java [duplicate]
What is a 2's complement of 2's complement. I know about 2's complement of a positive integer but what about negative integer.
What is a 2's complement of a negative integer eg: what is 2's complement ...
0
votes
1
answer
751
views
Which bit is the higher order bit in int type in java? [duplicate]
I read that in java, negative integers are obtained by taking 2's complement of a positive integer. In short, it also means that the higher order bit is being set to 1 in order to convert a positive ...
1
vote
5
answers
670
views
C language: left shift value with negative sign [duplicate]
I'm confused about the negation operation after doing the bit shift.
For example:
-(1<<7) is 0xffffff80
But why are the most significant bits filled with 1?
I'm confused about what the ...
Mike's user avatar
- 1,897
0
votes
1
answer
507
views
Why java int type has valid value in range -2,147,483,648 to 2,147,483,647? [duplicate]
I'm wondering why java int type (32 bit signed) has valid value in range -2,147,483,648 to 2,147,483,647 but not in (-2,147,483,648 to 2,147,483,648)?
2
votes
2
answers
529
views
Why negative signed integer with bitwise AND 0xFF will result in positive signed integer? [duplicate]
My goal is to understand the two's complement.
10000111 in signed integer equals to -121. However, if you bitwise AND it with 0xFF in hexadecimal or 11111111 in decimal, it will equals to 135.
In my ...
1
vote
3
answers
387
views
How does 11111111111111111111111111111110 evaluate to -2? [duplicate]
I was testing out the bitwise not operator in Java. I printed out the result of ~1 in binary, and it returned "11111111111111111111111111111110" which apparently evaluates to -2.
I know that you ...
1
vote
0
answers
373
views
In Java byte take 8 bits and range is -128 to 127 why it is not -127 to 128? [duplicate]
why range is not equally divided it can be -127 to 128. and if we consider range -128 to 127 then -128 can not be represented in 8 bits. -128 in binary 1100000000 first bit is for sign bit.
-2
votes
1
answer
126
views
How ~12 gives -13 in decimal? [duplicate]
I have a question in my programming class, it is: What is the value of ~12 and the answer is -13. I don't understand why? I convert 13 base 10 to binary, which is 1100, than I switched all the 1 for 0 ...
-3
votes
1
answer
154
views
Integer Overflow Java [duplicate]
I have a question in java about integer overflow.
When I search max integer and surfed integer for that binary, I got this "0111 1111 1111 1111 1111 1111 1111 1111" and also when I use the ...