// Compute the bitwise and, or, and exclusive or // of the inputs 82 and 107. // Hand computations: // Bitwise Or Bitwise And Bitwise XOr Bitwise Complement // Hex Binary Hex Binary Hex Binary // ==== ======== ==== ======== ==== ======== ================== // 82 -->01010010 82 -->01010010 82 -->01010010 82 -->01010010 // 107 -->01101011 107 -->01101011 107 -->01101011 -------- // -------- -------- -------- -83 <--10101101 // 123 <--01111011 66 <--01000010 57 <--00111001 // 107 -->01101011 // -------- // -108 -->10010100 public class Bitwise { public static void main(String[] args) { byte a = (byte) 82; byte b = (byte) 107; byte c; // Bitwise or. c = (byte) (a | b); System.out.printf("%X %d\n", c, c); // Bitwise and. c = (byte) (a & b); System.out.printf("%X %d\n", c, c); // Bitwise exclusive or. c = (byte) (a ^ b); System.out.printf("%X %d\n", c, c); // Bitwise complement. c = (byte) (~a); System.out.printf("%X %d\n", c, c); c = (byte) (~b); System.out.printf("%X %d\n", c, c); } } // Output: 7B 123 42 66 39 57 AD -83 94 -108