Shop OBEX P1 Docs P2 Docs Learn Events
Single Bit Access — Parallax Forums

Single Bit Access

crgwbrcrgwbr Posts: 614
edited 2007-11-05 19:31 in Propeller 1
Is there any way to set a specific bit of a variable to a 1 or 0? For example, if byte x == %00000000, I want to be able to set each individual bit separately from the others. Can I do this in SPIN? I haven't seen anything in the manual about it.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"... one of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs." -

"If Python is executable pseudocode, then perl is executable line noise."

"The best accelerator available for a Mac is one that causes it to go at 9.81 m/s2."

"My software never has bugs. It just develops random features."

"Windows isn't a virus, viruses do something."

"Programmers are tools for converting caffeine into code."

"Enter any 11-digit prime number to continue."

Comments

  • hippyhippy Posts: 1,981
    edited 2007-11-05 19:09
    variableName |= |< bitNumber    ' Set a bit
    
    variableName &= ! |< bitNumber ' Clear a bit
    
    
    
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-11-05 19:12
    to clear:
    var &= !(|< bit)
    to set:
    var |= |< bit

    where bit is the bit number (0,1,2,3,...,30,31)

    to test:
    var AND |< bit


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

    Parallax, Inc.
  • crgwbrcrgwbr Posts: 614
    edited 2007-11-05 19:31
    awesome, thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "... one of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs." -

    "If Python is executable pseudocode, then perl is executable line noise."

    "The best accelerator available for a Mac is one that causes it to go at 9.81 m/s2."

    "My software never has bugs. It just develops random features."

    "Windows isn't a virus, viruses do something."

    "Programmers are tools for converting caffeine into code."

    "Enter any 11-digit prime number to continue."
Sign In or Register to comment.