Skip to content

Commit dfc025d

Browse files
committed
further explanation of tilde in Java - add one bitwise
1 parent 43314f5 commit dfc025d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/javaSpecific/guessTheOutput/TildeMathematics.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
package javaSpecific.guessTheOutput;
22

3+
// -x = ~x + 1;
4+
// -~x = x + 1 (by replacing x by ~x)
35
public class TildeMathematics {
46
public static void main(String[] args) {
7+
System.out.println(~-9); // 8
8+
System.out.println(~-100); // 99
9+
System.out.println(~-1); // 0
10+
System.out.println(~-0); // -1
11+
512
System.out.println(~9); // -10
613
System.out.println(~100); // -101
714
System.out.println(~1); // -2

0 commit comments

Comments
 (0)