home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / pascal / 5120 < prev    next >
Encoding:
Text File  |  1992-08-30  |  1.6 KB  |  50 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!mcsun!sunic!kth.se!kjell
  3. From: kjell@elixir.e.kth.se (Kjell Rilbe)
  4. Subject: Re: reading Bit mapped fields
  5. Message-ID: <1992Aug31.094457.9196@kth.se>
  6. Sender: usenet@kth.se (Usenet)
  7. Nntp-Posting-Host: elixir.e.kth.se
  8. Organization: Dept. of EE, Royal Institute of Technology, Stockholm, Sweden
  9. References: <1992Aug31.094135.245@lincoln.ac.nz>
  10. Date: Mon, 31 Aug 1992 09:44:57 GMT
  11. Lines: 37
  12.  
  13. In article <1992Aug31.094135.245@lincoln.ac.nz> cachoo@lincoln.ac.nz writes:
  14. >
  15. >  var
  16. >    I : Integer;
  17. >    CheckBoxResult : Word;
  18. >    BitIsSet : Array[0..15] of Boolean;
  19. >  begin
  20. >    {get CheckBoxResult from user}
  21. >    for I := 0 to 15 do
  22. >      if CheckBoxResult AND I = I then BitIsSet[I] := True
  23. >      else BitIsSet[I] := False;
  24. >  end;
  25. >
  26. >As I understand TP instructions, this code should return the boolean 
  27. >equivalent of the binary value of CheckBoxResult. But it does not work! 
  28. >What am I doing wrong?
  29. >
  30. Well, Oscar, I usually do it this way:
  31.  
  32. BEGIN
  33.   FOR I:=0 TO 15 DO
  34.     BitIsSet[I]:=(CheckBoxResult AND (2 SHL I) > 0);
  35. END.
  36.  
  37. Note the direct boolean assignment replacing the if statement.
  38. The 2 SHL I calculates the mask for the I:th bit, and after AND:ing
  39. the result will be =0 if the bit was clear, and >0 if the bit was set.
  40.  
  41. Hope it helped!
  42.  
  43. /Kjell
  44.  
  45. -- 
  46. -----------------------------------------------------------------------------
  47. ! Kjell Rilbe           ! Love is not about getting everything on the list, !
  48. ! kjell@elixir.e.kth.se ! it's about accepting the things that aren't on    !
  49. !                       ! the list!             - Stewart Markowitz, LA Law !
  50.