_bittest、_bittest64

Microsoft 专用

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

语法

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

参数

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

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

返回值

指定位置的位。

要求

Intrinsic 体系结构 标头
_bittest x86、ARM、x64、ARM64 <intrin.h>
_bittest64 ARM64、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");
    }
}
Number: 78002
Binary representation:
0000000000000010011000010110010

结束 Microsoft 专用

另请参阅

编译器内部函数