注意:仔细注意位置。
public static int[] renderPixel(int[] screen, int x, int y){ int[] ans = new int[screen.length ]; int[] tmp = new int[screen.length * 8]; int t = 0; System.out.println(tmp[7]); for(int i = 0; i < screen.length; i++){ String str = Integer.toBinaryString(screen[i]); t=i*8; for(int j = str.length()-1; j >=0 ; j--){ tmp[t++] = str.charAt(j)-48; } } for(int i = x; i <= y; i++){ tmp[i] = 1; } System.out.println(); int flag = 0; for(int i = 0; i < tmp.length; ){ int digit = 0; for(int j = 0; j < 8; j++){ digit = (int) (digit + tmp[i+j] * Math.pow(2, j)); } ans[flag++] = digit; i = i + 8; } return ans; }