This week's book giveaway is in the Jobs Discussion forum.We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!See this thread for details.
Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login Win a copy of Java Interview Guide this week in the Jobs Discussion forum!

# Bitwise Inversion Operator

pelluru rao
Greenhorn

Joined: Aug 03, 2000
Posts: 5
Hello friends!!
This question is actually jargon.com
test3.html
the output of this programme is -7 .which is
unpredictable to me.
The ~(Bitwise Inversion Operator) inverts the
bit value.if so
for ~6 the output to be a large value but it is -7.
can any one give a suitable clue.
public class Test3Q40{
private void test() {
System.out.println(~6);
//00000000 00000000 00000000 00000110=6
}// 1111111111111111 11111111 11111001=?
static public void main(String[] a) {
new Test3Q40().test();
}
}
waiting for cordial replay.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
~6 = (-6) -1 = -7
-7 is 1111 1111 1111 1111 1111 1001
how is this ? negative numbers are represented in 2's complement form. so above bit pattern is a 2's complement representation of -7.
Here is how you get the 2's complement of -7,
7 in binary = 0000 0000 0000 0000 0000 0111
1's complement of 7 = 1111 1111 1111 1111 1111 1000
add 1 to it = 1111 1111 1111 1111 1111 1001

pelluru rao
Greenhorn

Joined: Aug 03, 2000
Posts: 5
now it is crystal clear.
ThankQ vasansini.

I agree. Here's the link: http://aspose.com/file-tools

subject: Bitwise Inversion Operator