bookmonkie
bookmonkie

Reputation: 449

Check if a single bit is zero

It's easy to check if a single bit in variable is 1. Ex. check if the third bit of variable is 1, just do

variable & 0100 ==0100

How to check if a single bit is 0?

Upvotes: 1

Views: 1375

Answers (1)

bookmonkie
bookmonkie

Reputation: 449

say you want to check the second bit is 0

targetBit = 0010

(~( variable) & targetBit ) == targetBit 

Upvotes: 1

Related Questions