| Author |
Operators
|
harish shankarnarayan
Ranch Hand
Joined: Sep 12, 2005
Posts: 158
|
|
class EBH012 { public static void main (String[] args) { byte x = 3, y = 5; //1 System.out.print((-x == ~x + 1)+","+(-y == ~y + 1)); }} ans is True true how??? can any one explain bit by bit wat happens
|
Harish<br />SCJP 1.4 (85%)
|
 |
bnkiran kumar
Ranch Hand
Joined: Mar 02, 2006
Posts: 171
|
|
Actually the highest precedence operators -,~ are evaluated first so ~3 is -4, and ~5 is -6. Then next highest priority operator + is evaluated, so lefthand value will be -3 which is equal to right hand operand. The result will be true,true.
|
Kiran Kumar.
|
 |
harish shankarnarayan
Ranch Hand
Joined: Sep 12, 2005
Posts: 158
|
|
so ~3 is -4, and ~5 is -6. can anyone explain how ~3 is -4 bit by bit
|
 |
 |
|
|
subject: Operators
|
|
|