Chinaunix首页 | 论坛 | 博客
  • 博客访问: 220598
  • 博文数量: 67
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 890
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-17 09:42
文章分类

全部博文(67)

文章存档

2010年(5)

2009年(7)

2008年(55)

我的朋友

分类: Java

2008-07-11 10:57:48

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) |
给主人留下些什么吧!~~