There are lots of ways of doing this.  The  C Language and assembly language
approach uses bit testing with AND.  Or if the instruction set supports it,
some sort of BIT TEST. which is what DELPHI does underneath the covers.. 

The more elegant Pascal method is to use sets which DELPHI turns into a BT
(Bit Test) instruction.

function TForm1.test( b : BYTE ) : BOOLEAN;
begin
  if b in [1,2,4,8,16,32,64,128] then
    test := TRUE
  else
    test := FALSE;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
        bch : BYTE;
begin
    bch := StrToInt(Edit1.text);
    if test(bch) then
        Edit1.text := 'In Set'
    else
        Edit1.text := 'Not In Set';

end;

Have fun.

John Dammeyer



Wireless CAN with the CANRF module now available.
http://www.autoartisans.com/products
Automation Artisans Inc.
Ph. 1 250 544 4950


> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Ross Levis
> Sent: Saturday, January 14, 2006 2:19 AM
> To: Delphi Discussion List
> Subject: bits
> 
> 
> Hi.
> 
> I then need a function that checks 1 bit of a byte value and returns 
> true or false representing 1 or 0.
> 
> function BitValue(Value,Bit: Byte): Boolean;
> begin
>   Result := ???
> end;
> 
> Bit has the range 0 to 7 or 1 to 8.
> 
> eg. BitValue(255,4) = True;
> 
> I've not done much binary manipulation before but I believe 
> it requires 
> AND, OR, or XOR, but I'm not sure how to do it.  Anyone?
> 
> Thanks,
> Ross. 
> 
> _______________________________________________
> Delphi mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi
> 
> 

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to