import java.util.Scanner;
public class andOperator {
// right shitf [/2 효과]
public static void operator_SHR (int param) {
System.out.printf("%d \n", param >> 1);
}
// left shift [x2 효과]
public static void operator_SHL (int param) {
System.out.printf("%d \n", param << 1);
/*
* 0000 1011 => 0001 0110 => 16 + 4 + 2 = 22
*/
}
// neg [2의 보수]
public static void operator_NEG (int param) {
System.out.printf("%d \n", ~param + 1); // 2의 보수
// 0000 1011
// 1111 0100 => -128 + (64 + 32 + 16 + 4) = -128 + 116 = -12 [1의 보수]
// -12 + 1 = -11 [2의 보수]
}
// not [1의 보수]
public static void operator_NOT (int param) {
System.out.printf("%d \n", ~param); // 1의 보수
}
public static void operator_XOR (int[] nParam) {
for (int i = 0; i < nParam.length; i++) {
for (int j = 0; j < nParam.length; j++) {
System.out.printf("%d xor %d = %d\n",
nParam[i], nParam[j], nParam[i] ^ nParam[j]);
}
}
}
public static void operator_AND (int[] nParam) {
for (int i = 0; i < nParam.length; i++) {
for (int j = 0; j < nParam.length; j++) {
System.out.printf("%d and %d = %d\n",
nParam[i], nParam[j], nParam[i] & nParam[j]);
}
}
}
public static void operator_OR (int[] nParam) {
for (int i = 0; i < nParam.length; i++) {
for (int j = 0; j < nParam.length; j++) {
System.out.printf("%d or %d = %d\n",
nParam[i], nParam[j], nParam[i] | nParam[j]);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
// OR
int[] number = {1, 0};
int nData = 11;
operator_OR(number);
operator_AND(number);
operator_XOR(number);
operator_NOT(nData);
operator_NEG(nData);
operator_SHR(nData);
}
}