home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!mcsun!sunic!kth.se!kjell
- From: kjell@elixir.e.kth.se (Kjell Rilbe)
- Subject: Re: reading Bit mapped fields
- Message-ID: <1992Aug31.094457.9196@kth.se>
- Sender: usenet@kth.se (Usenet)
- Nntp-Posting-Host: elixir.e.kth.se
- Organization: Dept. of EE, Royal Institute of Technology, Stockholm, Sweden
- References: <1992Aug31.094135.245@lincoln.ac.nz>
- Date: Mon, 31 Aug 1992 09:44:57 GMT
- Lines: 37
-
- In article <1992Aug31.094135.245@lincoln.ac.nz> cachoo@lincoln.ac.nz writes:
- >
- > var
- > I : Integer;
- > CheckBoxResult : Word;
- > BitIsSet : Array[0..15] of Boolean;
- > begin
- > {get CheckBoxResult from user}
- > for I := 0 to 15 do
- > if CheckBoxResult AND I = I then BitIsSet[I] := True
- > else BitIsSet[I] := False;
- > end;
- >
- >As I understand TP instructions, this code should return the boolean
- >equivalent of the binary value of CheckBoxResult. But it does not work!
- >What am I doing wrong?
- >
- Well, Oscar, I usually do it this way:
-
- BEGIN
- FOR I:=0 TO 15 DO
- BitIsSet[I]:=(CheckBoxResult AND (2 SHL I) > 0);
- END.
-
- Note the direct boolean assignment replacing the if statement.
- The 2 SHL I calculates the mask for the I:th bit, and after AND:ing
- the result will be =0 if the bit was clear, and >0 if the bit was set.
-
- Hope it helped!
-
- /Kjell
-
- --
- -----------------------------------------------------------------------------
- ! Kjell Rilbe ! Love is not about getting everything on the list, !
- ! kjell@elixir.e.kth.se ! it's about accepting the things that aren't on !
- ! ! the list! - Stewart Markowitz, LA Law !
-