import core.bitop;
int main()
{
assert(bsf(0x21) == 0);
return 0;
}
import core.bitop;
int main()
{
assert(bsr(0x21) == 5);
return 0;
}
| uint* p | a non-NULL pointer to an array of size_ts. |
| index | a bit number, starting with bit 0 of p[0],
and progressing. It addresses bits like the expression:
p[index / (size_t.sizeof*8)] & (1 << (index & ((size_t.sizeof*8) - 1))) |
import std.stdio;
import core.bitop;
int main()
{
size_t array[2];
array[0] = 2;
array[1] = 0x100;
assert(btc(array, 35) == 0);
assert(array[0] == 2);
assert(array[1] == 0x108);
assert(btc(array, 35) == -1);
assert(array[0] == 2);
assert(array[1] == 0x100);
assert(bts(array, 35) == 0);
assert(array[0] == 2);
assert(array[1] == 0x108);
assert(btr(array, 35) == -1);
assert(array[0] == 2);
assert(array[1] == 0x100);
assert(bt(array, 1) == -1);
assert(array[0] == 2);
assert(array[1] == 0x100);
return 0;
}