Shop OBEX P1 Docs P2 Docs Learn Events
Booleans and Bytes — Parallax Forums

Booleans and Bytes

codekingcodeking Posts: 39
edited 2007-01-08 18:42 in Propeller 1
Are there booleans in spin? They don't mention it in the manual.
Can you take 8 booleans and change them into a byte?


Thanks,
Theron
Mark Twain said...
There are only two things that are infinite. Human stupidity and the universe. I'm not sure about the latter.

Comments

  • NewzedNewzed Posts: 2,503
    edited 2007-01-07 17:01
    The term "Boolean" refers to a mathematical methodology.· It has no meaning, per se, as bits or bytes.· Search for Boolean Math on the web.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Don't have VGA?

    Newzed@aol.com
    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-07 17:03
    Booleans internally are the values false and true. False is defined as zero and true is defined as non-zero although it's -1 by default (all one bits). As such, Boolean values are just integers. You can pack them 8 per byte, but you'll have to do it yourself. If you keep Boolean true as -1, you could do something like:
       value := (bool[noparse][[/noparse]7] & %10000000) | (bool[noparse][[/noparse]6] & %01000000) | (bool & %00100000) | (bool & %00010000) ...
    or
       bool[noparse][[/noparse]7] := value & %10000000 <> 0
       bool[noparse][[/noparse]6] := value & %01000000 <> 0
    
    
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-01-08 18:42
    You can also provide "named" booleans, like so:

    CON
      firstflag = |< 0
      secondflag = |< 1
      thirdflag = |< 2
    'more flag definitions here
     
    VAR
      long flags
     
     
    PUB go
      flags |= firstflag   'set the first flag
      flags &= !secondflag 'clear the second flag
      if flags & firstflag
        'code to execute if first flag set
      if !flags & secondflag
        'code to execute if second flag is clear
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
Sign In or Register to comment.