This topic has not yet been rated - Rate this topic

_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
);
[in] a

A pointer to the memory to examine.

[in] b

The bit position to test.

The bit at the position specified.

Intrinsic

Architecture

_bittest

x86, IPF, x64

_bittest64

IPF, x64

Header file <intrin.h>

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
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
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.