Export (0) Print
Expand All
Expand Minimize

_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

Community Additions

ADD
Show:
© 2014 Microsoft