_bittest, _bittest64

Microsoft 专用

生成 bt 指令,从而检查地址 a 的位置 b 中的位,并返回该位的值。

unsigned char _bittest(    long *a,    long b ); unsigned char _bittest64(    __int64 *a,    __int64 b );

参数

  • [in] a
    指向要检查的内存的指针。

  • [in] b
    要测试的位位置。

返回值

指定位置的位。

要求

内部函数

体系结构

Header

_bittest

x86、ARM、x64

<intrin.h>

_bittest64

ARM、x64

<intrin.h>

备注

此例程仅可用作内部函数。

示例

// bittest.cpp
// processor: x86, ARM, 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");
    }
}
  

请参见

参考

编译器内部函数