This documentation is archived and is not being maintained.

_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


x86, IPF, x64


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


Number: 78002
Binary representation: