turning off a particular bit in a number

ali0482ali0482 Registered Users Posts: 1 ■□□□□□□□□□
Which bit wise operator is suitable for turning off a particular bit in a number ?

Comments

  • undomielundomiel Member Posts: 2,818
    Odd question. If you turn off a bit in a number that changes the number. You would want to use &

    i.e.

    170 (10101010b) & 255 (11111111b) will yield 170, but if you do 170 (10101010b) & 207 (11001111b) you will get 138 (10001010)

    As you can see when a bit is on (1) then the bitwise and will leave the corresponding bit in the state that it was in, but if the bit is off (0) then it will turn off the corresponding bit.
    Jumping on the IT blogging band wagon -- http://www.jefferyland.com/
Sign In or Register to comment.