# VBForums CodeBank > CodeBank - Other >  Fast Bit Check (Inline Assembly)

## Zervic

First off, credits go to a friend...

Using the following:
http://thundervb.profitux.cz/go.php?adr=home


VB Code:
'Note double dereference because passing byref
Public Function CheckBits(lngNumber As Long, lngTest As Long) As Boolean
    '#asm'  mov eax,[esp+4]             ;Move pointer to lngNumber into eax
    '#asm'  mov eax,[eax]               ;Move value of lngNumber into eax
    '#asm'  mov ecx,[esp+8]
    '#asm'  mov ecx,[ecx]
    '#asm'  not eax
    '#asm'  test eax,ecx                ;And the value of lngNumber with lngTest and effect SF, ZF, and PF
    '#asm'  .IF !ZERO?                  ;Is the zero flag not set (bit set)
    '#asm'      xor eax,eax             ;Return false
    '#asm'  .ELSE
    '#asm'      mov eax,-1              ;Return true
    '#asm'  .ENDIF
    '#asm'  ret 8
End Function

However, he had to write a second one for those cases where Visual Basic's signed long can't hold a mask capable of checking every bit in an unsigned long. Work with file formats, you will understand why you need the speed of assembly and unsigned longs .


VB Code:
Public Function CheckBitNumber(lngNumber As Long, lngBitNumber As Long) As Boolean
    '#asm'  mov ecx,[esp+8]             ;Calculate 2^(lngBitNumber - 1) and place it in eax
    '#asm'  mov cl,[ecx]
    '#asm'  dec cl
    '#asm'  mov eax,1
    '#asm'  shl eax,cl
    
    '#asm'  mov ecx,[esp+4]             ;Move pointer to lngNumber into ecx
    '#asm'  mov ecx,[ecx]               ;Move value of lngNumber into ecx
     '#asm'  test eax,ecx                ;And the value of lngNumber with lngTest and effect SF, ZF, and PF
    '#asm'  .IF ZERO?                   ;Is the zero flag set (bit not set)
    '#asm'      xor eax,eax             ;Return false
    '#asm'  .ELSE
    '#asm'      mov eax,-1              ;Return true
    '#asm'  .ENDIF
    '#asm'  ret 8
End Function

Enjoy  :Smilie:

----------


## Hack

Moved from CodeBank VB6

----------


## Zervic

> Moved from CodeBank VB6


However, it is indeed visual basic, its just using inline asm  :Smilie:  Just thought I'd let you know.

----------

