Operators and Numbers
int x = 2; System.out.println("Binary string version of x: " + Integer.toBinaryString(x)); x = x << 1; // Predicted decimal value: 4, binary string: 100 System.out.println("x in decimal form: " + x); System.out.println("x in binary notation: " + Integer.toBinaryString(x));int x = 9; System.out.println("Binary string version of x: " + Integer.toBinaryString(x)); x = x << 1; // Predicted decimal value: 18, binary string: 10010 System.out.println("x in decimal form: " + x); System.out.println("x in binary notation: " + Integer.toBinaryString(x));int x = 17; System.out.println("Binary string version of x: " + Integer.toBinaryString(x)); x = x << 1; // Predicted decimal value: 34, binary string: 100010 System.out.println("x in decimal form: " + x); System.out.println("x in binary notation: " + Integer.toBinaryString(x));int x = 88; System.out.println("Binary string version of x: " + Integer.toBinaryString(x)); x = x << 1; // Predicted decimal value: 176, binary string: 10110000 System.out.println("x in decimal form: " + x); System.out.println("x in binary notation: " + Integer.toBinaryString(x));int x = 150; System.out.println("Binary string version of x: " + Integer.toBinaryString(x)); x = x >> 2; // Predicted decimal value: 37, binary string: 100101 System.out.println("x in decimal form: " + x); System.out.println("x in binary notation: " + Integer.toBinaryString(x));int x = 225; System.out.println("Binary string version of x: " + Integer.toBinaryString(x)); x = x >> 2; // Predicted decimal value: 56, binary string: 111000 System.out.println("x in decimal form: " + x); System.out.println("x in binary notation: " + Integer.toBinaryString(x));int x = 1555; System.out.println("Binary string version of x: " + Integer.toBinaryString(x)); x = x >> 2; // Predicted decimal value: 388, binary string: 110000100 System.out.println("x in decimal form: " + x); System.out.println("x in binary notation: " + Integer.toBinaryString(x));int x = 32456; System.out.println("Binary string version of x: " + Integer.toBinaryString(x)); x = x >> 2; // Predicted decimal value: 8114, binary string: 111111001010 System.out.println("x in decimal form: " + x); System.out.println("x in binary notation: " + Integer.toBinaryString(x));int x = 7, y = 17; // Predicted result: decimal: 1, binary: 1 int z = x & y; System.out.println("z in decimal form: " + z); System.out.println("z in binary notation: " + Integer.toBinaryString(z));int x = 7, y = 17; // Predicted result: decimal: 23, binary: 10111 int z = x | y; System.out.println("z in decimal form: " + z); System.out.println("z in binary notation: " + Integer.toBinaryString(z));int x = 5; System.out.println("x before increment: " + x); x++; System.out.println("x after increment: " + x);int x = 3; System.out.println("x before increment: " + x); x = x + 1; System.out.println("x after increment: " + x); x += 1; System.out.println("x after increment: " + x); x++; System.out.println("x after increment: " + x);int x = 5, y = 8; int sum = ++x + y; System.out.println("sum: " + sum);int x = 5, y = 8; int sum = x++ + y; System.out.println("sum: " + sum);
Last updated