bts

Tests and sets the bit.

nothrow @safe @nogc pure @system
int
bts
(
size_t* p
,
size_t bitnum
)

Parameters

p
Type: size_t*

a non-NULL pointer to an array of size_ts.

bitnum
Type: size_t

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)))

Return Value

Type: int

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

Examples

1 size_t[2] array;
2 
3 array[0] = 2;
4 array[1] = 0x100;
5 
6 assert(btc(array.ptr, 35) == 0);
7 if (size_t.sizeof == 8)
8 {
9     assert(array[0] == 0x8_0000_0002);
10     assert(array[1] == 0x100);
11 }
12 else
13 {
14     assert(array[0] == 2);
15     assert(array[1] == 0x108);
16 }
17 
18 assert(btc(array.ptr, 35));
19 assert(array[0] == 2);
20 assert(array[1] == 0x100);
21 
22 assert(bts(array.ptr, 35) == 0);
23 if (size_t.sizeof == 8)
24 {
25     assert(array[0] == 0x8_0000_0002);
26     assert(array[1] == 0x100);
27 }
28 else
29 {
30     assert(array[0] == 2);
31     assert(array[1] == 0x108);
32 }
33 
34 assert(btr(array.ptr, 35));
35 assert(array[0] == 2);
36 assert(array[1] == 0x100);
Suggestion Box / Bug Report