public class Test {
public static void main(String[] args) {
int[] Hash = new int[8];
Test test = new Test();
for (int a = 0; a < 256; a++) {
test.Input(Hash, a);
}
// test.Input(Hash, 30);
test.Output(Hash);
}
public void Input(int[] Hash, int a) {
int index_int = a & 31;//34%32
int index_Hash = (a >> 5) & 7;//(34/32)%8
if ((Hash[index_Hash] & (1 << index_int)) == (1 << index_int)) {
System.out.println("此数已存在");
} else {
Hash[index_Hash] = Hash[index_Hash] | (1 << index_int);
//输入数组中元素的情况
// System.out.println("i="+Hash[index_Hash]+":"+Integer.toBinaryString(Hash[index_Hash]));
}
}
public void Output(int[] Hash) {
//输出数组
// for (int i = 0; i < 8; i++) {
// System.out.println("Hash[" + i + "]=" + Hash[i]);
// }
for (int i = 0; i < 8; i++) {
int b = i * 32;
for (int j = 0; j < 32; j++) {
if ((Hash[i] & (1 << j)) == (1 << j)) {
System.out.println("b=" + (b + j));
}
}
}
}
}
阅读(1143) | 评论(0) | 转发(0) |