var
i: word;
j: word;
k: word;
begin
i := 7;
j := 123;
k := (i and $f) shl 12 or (j and $fff); // merge 4 bits from i and12 from j
// and back split k
i := (k shr 12) and $f;
j := k and $fff;
showMessage(IntToStr(k));
showMessage(IntToStr(i));
showMessage(IntToStr(j));
Main Topics
Browse All Topics





by: ziolkoPosted on 2008-04-22 at 13:20:47ID: 21415175
procedure SetBit(var AValue:Integer; ABitNo: Word);
begin
AValue := AValue or (1 shl ABitNo);
end;
function IsBitSet(BitMask: Integer; ABitNo: Byte): Boolean;
var v: Integer;
begin
v := 1 shl ABitNo;
Result := BitMask and v = v;
end;
note that bit 0 is right most bit
there's no range checking
ziolko.