setting a bit on a ram variable

Discussion in 'Sega Discussion' started by Scorpion Illuminati, Nov 10, 2015.

  1. Scorpion Illuminati

    Scorpion Illuminati Scorpion Illuminati Lead Developer(Site Supporter)

    Joined:
    Oct 1, 2015
    Messages:
    15
    Likes Received:
    1
    Location:
    Cyber Space
    Lets say i have a Byte variable called flags. As you know an integer has 8 bits.
    Code:
    7-6-5-4-3-2-1-0
    
    How would I set bit X where x is 0 to 7? For example:
    Code:
    flags       equ (audio_clock+SizeByte)
    
    FLAG_FRET_GREEN       equ 0x1
    FLAG_FRET_RED           equ 0x2
    FLAG_FRET_YELLOW    equ 0x4
    
    // now set it
    ?????
    
    I want to set a bit without effecting the other ones. Any assistance in this matter would be greatly appreciated.

    Sincerely,

    Scorpion Illuminati
     
    #1
  2. rso

    rso Familiar Face

    Joined:
    Mar 26, 2010
    Messages:
    1,162
    Likes Received:
    39
    Location:
    Germany
    Simply OR the current value with the bitmask. And re-/unset by ANDing it with the inverse of the mask.
     
    #2

Share This Page