Non ho capito bene il problema ma puoi testare i bit con l'operatore &