//arr[n]的第m位置1 voidsetBit(int num,int arr[]) { int n = num / 32; int m = num % 32; arr[n] += (1 << m); } //地位至高位打印 voidprintBitMap(int arr[],int len) { for (int i = 0; i<len; i++) { int n = 1; for (int ii = 0; ii < 32; ++ii) { if ((arr[i] & n) == n)//这里时==n,不是==1 { cout << i * 32 + ii << endl; } n <<= 1; } } } voidclr(int arr[], int len) { for (int i = 0; i < len; ++i) arr[i] = 0; } intmain() { int arr[100]; int arr2[10] = { 100,800,22,314,21,44,0,1,3,2 }; clr(arr,100); for(int i = 0; i < 10; ++i) { setBit(arr2[i], arr); } printBitMap(arr, 100); return0; }