Autor Beitrag
Jacdelad
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109

Win XP Pro
Borland Developer Studio 2006 Architect
BeitragVerfasst: Fr 07.04.06 15:34 
Hallo, kann mir jemand sagen, wie ich ein einzelnes Bit eines Integers abfragen kann (also Bit 0..31)?

Jac
Allesquarks
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 510

Win XP Prof
Delphi 7 E
BeitragVerfasst: Fr 07.04.06 15:39 
Über den AND Operator:

myinteger AND 00000...0100b zum Auslesen des dritten Bits.

bzw.:

myinteger AND intpower(2,myBit-1)
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Fr 07.04.06 15:53 
Hallo,

oder
ausblenden Delphi-Quelltext
1:
2:
3:
4:
function TesteBitGesetzt(i:integer,Pos:integer): boolean;
begin
 result := (i AND (1  shl pos))<>0;
end;


Man muesste Pos noch auf 0..31 testen etc.

Gruss Horst
Jacdelad Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109

Win XP Pro
Borland Developer Studio 2006 Architect
BeitragVerfasst: Fr 07.04.06 16:01 
Ahh, danke!
Und wie kann ich eins setzen???

Jac
Allesquarks
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 510

Win XP Prof
Delphi 7 E
BeitragVerfasst: Fr 07.04.06 16:03 
Mit oder und Zuweisung in die Variable:

myinteger:=myinteger OR 000...100b

drittes Bit gesetzt.
Jacdelad Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109

Win XP Pro
Borland Developer Studio 2006 Architect
BeitragVerfasst: Fr 07.04.06 16:06 
Vielen Dank!