第一题:class BinDemo{ public static void main(String[] args){ //左移:首位符号位 一定会移动掉,因此没有(有|无)符号位移动一说。 byte plus_left = 9; byte minus_left = -9; System.out.println(plus_left << 2);//0000 1001 => 0010 0100 = 36 System.out.println(minus_left << 2);//11111 0111 移动补码 => 1101 1100 补码 => 1010 0100原码 = -36 //有符号右移:正数补0,负数补1,符号位正常移动。 byte plus_right = 9; byte minus_right = -9; System.out.println(plus_right >> 2);//0000 1001 => 0000 0010 = 2 System.out.println(minus_right >> 2);//1111 0111 移动补码 => 1111 1101 补码 => 1000 0011原码 = -3 //无符号右移:正数补0,负数补1,符号位不移动。 byte unsigned_plus_right = 9; byte unsigned_minus_right = -9; System.out.println(unsigned_plus_right >>> 2);//0000 1001 => 0000 0010 = 2 System.out.println((byte)(unsigned_minus_right >>> 2));//1111 0111 移动补码 => 1111 1101 补码 => 1000 0011原码 = -3 byte unsigned_minus_right2 = -5; System.out.println((byte)(unsigned_minus_right2 >>> 2));//1111 1011 移动补码 =>1111 1110 补码 => 1000 0010原码 = -2 }}第二题:class BinDemo{ public static void main(String[] args){ String hex_value = changeHex(11); System.out.println(hex_value); } public static String changeHex(int v){ int lower = v & 0x0F; int upper = (v >> 4) & 0x0F; char[] arr = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E'}; return "0x" + arr[upper] + arr[lower]; }}第三题:class BinDemo{ public static void main(String[] args){ int sum_value = getSum(new int[]{1,5,7,9}); System.out.println(sum_value); } public static int getSum(int[] arr){ int length = arr.length; int total = 0; for(int i=0;i :设置初始java堆大小。 java -Xmx :设置最大java堆大小。