_bittest, _bittest64
Microsoft Specific
Generates the bt instruction, which examines the bit in position b of address a, and returns the value of that bit.
unsigned char _bittest( long *a, long b ); unsigned char _bittest64( __int64 *a, __int64 b );
On the IPF architecture, the bt instruction is not available, so this intrinsic is a custom function that imitates the behavior of bt. This custom function might be slower than a hand-written inline function because it includes overhead, such as handling the case where b is negative, that might be unnecessary in specific cases.
This routine is only available as an intrinsic.
// bittest.cpp
// processor: x86, IPF, x64
#include <stdio.h>
#include <intrin.h>
long num = 78002;
int main()
{
unsigned char bits[32];
long nBit;
printf_s("Number: %d\n", num);
for (nBit = 0; nBit < 31; nBit++)
{
bits[nBit] = _bittest(&num, nBit);
}
printf_s("Binary representation:\n");
while (nBit--)
{
if (bits[nBit])
printf_s("1");
else
printf_s("0");
}
}
Number: 78002 Binary representation: 0000000000000010011000010110010
Is the return value always true or false?
Please clarify whether the return value is always either 0 or 1, i.e. true or false, or whether the bit that is set will have the same value as the test mask.
- 9/21/2011
- Tim Randall