algorithm - Four variables, how to quickly check all of them are either 1 or 0? -


i have 4 integer variables a, b, c , d. want know if of them of values 1 or 0. apparently can use if statement check like:

if((a == 0 || == 1) && (b == 0 || b == 1) &&    (c == 0 || c == 1) && (d == 0 || d == 1)) {     print(true) } else {     print(false) } 

it's bit boring write of that. i'm thinking if there methods use bit operations solve issue. don't have clue it. can point me right direction? or there other simpler way check that?

in c, take bitwise or, , test that:

int e = a|b|c|d; return e==0 || e==1; 

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -