tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: 64-bit masks
>> int first_free(uint64_t m)
>> {
>> m = (~m) & ~((~m)-1);
>> if (! m) return(-1);
>> return( ((m & 0xffffffff00000000ULL) ? 32 : 0) +
>> ((m & 0xffff0000ffff0000ULL) ? 16 : 0) +
>> ((m & 0xff00ff00ff00ff00ULL) ? 8 : 0) +
>> ((m & 0xf0f0f0f0f0f0f0f0ULL) ? 4 : 0) +
>> ((m & 0xccccccccccccccccULL) ? 2 : 0) +
>> ((m & 0x5555555555555555ULL) ? 1 : 0) );
>> }
> for m = 0x7 (binary 00000111), first_free() returns 2, which is
> wrong.
Doh! My mistake. 0xaaaaaaaaaaaaaaaa, not 0x5555555555555555.
(Everything was working fine, except it was numbering the bits going
... 6 7 4 5 2 3 0 1 rather than ... 7 6 5 4 3 2 1 0, because I got that
mask complemented.)
/~\ The ASCII Mouse
\ / Ribbon Campaign
X Against HTML mouse%rodents-montreal.org@localhost
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
Home |
Main Index |
Thread Index |
Old Index