views:

74

answers:

3

For a particular application using bitwise masks to store a value, I'd like to perform a certain bitwise filter, but I'm not sure what it's called, or how you'd actually do it in a sensible way.

// I'll just refer to the operator as "?" for the sake of example:
Input1 ? Input2 = Output
     0 ? 0      = 0
     0 ? 1      = 0
     1 ? 0      = 1
     1 ? 1      = 0

  101      110      1100
? 111    ? 100    ? 1010
= 000    = 010    = 0100

My language is PHP, but any explanation is welcome.

+8  A: 

From PHP bitwise operators:

$a & ~$b

meaning (a AND NOT b)

cletus
+4  A: 

In C:

Input1 & ~Input2
Michael Burr
+3  A: 

It's not a single operator

Output = Input1 AND NOT(Input2)

pavium