bts

Tests and sets the bit.

bts
(
Field
T = typeof(Field.init[size_t.init])
)
(
auto ref Field p
,
size_t bitnum
)
if (
__traits(isUnsigned, T)
)

Parameters

p Field

a non-NULL field / pointer to an array of unsigned integers.

bitnum size_t

a bit number, starting with bit 0 of p[0], and progressing. It addresses bits like the expression:

p[index / (T.sizeof*8)] & (1 << (index & ((T.sizeof*8) - 1)))

Return Value

Type: auto

A non-zero value if the bit was set, and a zero if it was clear.

Examples

size_t[2] array;

array[0] = 2;
array[1] = 0x100;

assert(btc(array.ptr, 35) == 0);
if (size_t.sizeof == 8)
{
    assert(array[0] == 0x8_0000_0002);
    assert(array[1] == 0x100);
}
else
{
    assert(array[0] == 2);
    assert(array[1] == 0x108);
}

assert(btc(array.ptr, 35));
assert(array[0] == 2);
assert(array[1] == 0x100);

assert(bts(array.ptr, 35) == 0);
if (size_t.sizeof == 8)
{
    assert(array[0] == 0x8_0000_0002);
    assert(array[1] == 0x100);
}
else
{
    assert(array[0] == 2);
    assert(array[1] == 0x108);
}

assert(btr(array.ptr, 35));
assert(array[0] == 2);
assert(array[1] == 0x100);

Meta