假如要使一個char數組或者byte數組中的每一位應該怎么做?
下面是我的方案。但是不成功。請指點
public static void main(String[] args) {??int[] A=new int[]{2,34,6,15,7,8,9,93,100};??byte[] c=new byte[13];??//設置所有的位都為0??for(int i=0;i<13;i++){????c[i]=(byte) ((byte)c[i]&0x0);??}??//數組加入到c中??c=setBit(c,A);??//輸出c??outPut(c);?}?public static byte[] setBit(byte[] c,int[] num){??for(int i=0;i<num.length;i++){???int j=num[i]/8;//一個字節八位???c[j]=(byte) ((int)c[j]|(0x1<<(j%8)));??}??return c;?}?public static void outPut(byte[] c){??for(int i=0;i<c.length;i++){???for(int k=0;k<8;k++){????if((c[k]&1<<k)==(1<<k)){?????System.out.print(i*8+k+"? ");????}???}??}?}
如何用JAVA或者C#實現bit-map
慕碼人2483693
2018-12-07 06:14:34