This function will isolate a bit array in a 32-bit integer and return the array to the caller. Value is the source array, Start is the bit index number (0..31) for the start of the array and Count contains the length of the array to be extracted.
function ExtractBits(const Value, Start, Count: Integer): Integer;
const
Mask: array[0..31] of Integer =
($01,$03,$07,$0F,$1F,$3F,$7F,$FF,
$01FF,$03FF,$07FF,$0FFF,$1FFF,$3FFF,$7FFF,$FFFF,
$01FFFF,$03FFFF,$07FFFF,$0FFFFF,
$1FFFFF,$3FFFFF,$7FFFFF,$FFFFFF,
$01FFFFFF,$03FFFFFF,$07FFFFFF,$0FFFFFFF,
$1FFFFFFF,$3FFFFFFF,$7FFFFFFF,$FFFFFFFF);
asm
xchg ecx, edx
test edx, edx
jnz @@isoke
xor eax, eax
jmp @@ending
@@isoke:
dec edx
and edx, 31
shr eax, cl
and eax, dword ptr [Mask+edx*4]
@@ending:
end;
Source: www.guidogybels.net.