_bittest, _bittest64

 

The latest version of this topic can be found at _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.

Syntax

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

Parameters

[in] a
A pointer to the memory to examine.

[in] b
The bit position to test.

Return Value

The bit at the position specified.

Requirements

Intrinsic Architecture Header
_bittest x86, ARM, x64 <intrin.h>
_bittest64 ARM, x64 <intrin.h>

Remarks

This routine is only available as an intrinsic.

Example

// 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 Specific

See Also

Compiler Intrinsics