Array offset and bit #
I was wondering what an array offset and what an array bit # is?
for example an array offset in like a hash function. Suppose you are given x as a parameter to the hash function. The array offset could be x>>5 (x/32). The bit number could be x&0x1F (x%32). What I don't get is what constitutes an offset and what constitutes a "bit number".
Oh yes the array is an array to pointer of integers. so...int* array[size];
开发者_如何学运维Thanks
It sounds like the code you are talking about is accessing bits in an array of 32-bit ints. So, say, bit #0 overall would be bit #0 of int #0, bit #31 overall would be bit #31 of int #0, bit #32 overall would be bit #0 of int #1 (since you ran out of bits in int #0), etc.
So the int# to look at is the your overall bit# divided by 32 (since each int uses up 32 bits), and the bit# to look at in that int is what's left over after you divide by 32.
The bit arithmetic you mention with x >> 5
and x & 0x1F
is just a fast way to perform those operations.
精彩评论