Anyone in this thread know programming? I got some code off the net and can't figure out what it is doing:
(the stuff inside the for loop). what does the >> do? and is the 0xFF about comparing bytes?
*has never used bytes before and is confused*
uint h;
for (h = 0, i = 0; i < 625; i++) {
j=k;
h += cuByteOnes[(j>> 24) & 0xFF];
h += cuByteOnes[(j>> 16) & 0xFF];
h += cuByteOnes[(j>> 8) & 0xFF];
h += cuByteOnes[(j ) & 0xFF];
}
uint[] cuByteOnes = {
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, // 00-0F
....
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 //F0-FF
};
>> is a bitwise shift.
& 0xFF is a bit mask. So take the binary representation of the value of j(32 bits total), then chop off the 24 bits on the right. Take the resulting 8 bits and mask them (this actually gives you the same value). then do the same thing except only shift by 16 bits. So this time the value being masked will be 16 bits, so you'll be chopping off the left 8 bits.
|01101011|10101101|00001011|11001011
|. . j>>24.|..J>>16...|....j>>8...|.......j
In other words...
It shifts and masks so that you get exactly a byte(8 bits) of data on each line. So if you're given 32 bits, it gives you the fourth byte, then the third byte, then the second byte, then the first byte.