分享方式:


_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]要測試的位位置。

傳回值

位於指定位置的位元。

需求

內建 架構 標題
_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

END Microsoft 特定的

另請參閱

編譯器內建函式