[fpc-pascal] Re: Why does this work?

Reinier Olislagers reinierolislagers at gmail.com
Fri Apr 12 12:08:51 CEST 2013


On 12-4-2013 12:01, Ludo Brands wrote:
> On 04/12/2013 11:47 AM, Reinier Olislagers wrote:
>>   if (FNullField <> nil) and (Dst = nil) and (AFieldDef.NullPosition >=
>> 0) then
>>   begin
>>     Src := PChar(Src) + FNullField.Offset + (AFieldDef.NullPosition shr 3);
>>     Result := (PByte(Src)^ and (1 shl (AFieldDef.NullPosition and $7))) = 0;
>>     exit;
>>   end;
>>
> 
> NullPosition is a bit position, 8 bits in a byte. To find bit x you have
> to look in byte Start + x div 8. x div 8 can be written as x shr 3. Now
> that you have found the byte where bit x is you need to isolate that
> bit. Its position in the byte is X mod 8 which you can write as X and
> $7. The 1 shl (X and $7) is done to create a mask to get the correct bit.
> 
> Ludo

Thanks Marco & Ludo,

The penny finally dropped.

Regards,
Reinier




More information about the fpc-pascal mailing list