You must evaluate '0'´s and '1'´s separatelly.
Try this :
Code:
\\ iWord <= input operator pattern in which pins to be toggled bits are designed by '1'
\\ PORTx <= global variable representing I/O uC port
int iTemp = PORTx ;
PORTx &= ~ ( iWord & iTemp ) ;
PORTx |= ( ~iWord & iTemp ) ;