_bittest64、_bittest
[このドキュメントはプレビュー版であり、後のリリースで変更されることがあります。 Blank topics are included as placeholders.]
Microsoft 固有の仕様 →
アドレス a の場所 b ビットを調べる生成しそのビットの値を返します bt について説明します。
unsigned char _bittest(
long *a,
long b
);
unsigned char _bittest64(
__int64 *a,
__int64 b
);
パラメーター
[入力] a
チェックするメモリへのポインター。[入力] b
テストするビット位置。
戻り値
指定した位置のビット。
必要条件
組み込み |
アーキテクチャ |
---|---|
_bittest |
x86IPFx64 |
_bittest64 |
はx64 |
ヘッダー ファイル <intrin.h>
解説
はアーキテクチャではbt 命令は使用できないためこの組み込みでは bt の動作をシミュレートするカスタム関数です。 この関数はカスタム オーバーヘッドが含まれているため特定の場合は不要である可能性もある b が負の値である場合の処理など手書きのインライン関数より遅い場合があります。
このルーチンは組み込みとしてのみ使用できます。
使用例
// 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");
}
}