View source code
Display the source code in core/bitop.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function core.bitop.bts
Tests and sets the bit.
int bts
(
ulong* p,
ulong bitnum
) pure nothrow @nogc;
Parameters
Name | Description |
---|---|
p | a non-NULL pointer to an array of size_ts. |
bitnum | 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))) --- |
Returns
A non-zero value if the bit was set, and a zero if it was clear.
Example
size_t[2] array;
array[0] = 2;
array[1] = 0x100;
writeln(btc(array .ptr, 35)); // 0
if (size_t .sizeof == 8)
{
writeln(array[0]); // 0x8_0000_0002
writeln(array[1]); // 0x100
}
else
{
writeln(array[0]); // 2
writeln(array[1]); // 0x108
}
assert(btc(array .ptr, 35));
writeln(array[0]); // 2
writeln(array[1]); // 0x100
writeln(bts(array .ptr, 35)); // 0
if (size_t .sizeof == 8)
{
writeln(array[0]); // 0x8_0000_0002
writeln(array[1]); // 0x100
}
else
{
writeln(array[0]); // 2
writeln(array[1]); // 0x108
}
assert(btr(array .ptr, 35));
writeln(array[0]); // 2
writeln(array[1]); // 0x100
Authors
Don Clugston, Sean Kelly, Walter Bright, Alex Rønne Petersen, Thomas Stuart Bockman
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.