You cannot completely restore all bits.
B << 3 moves βBβ three bits to the left, and it does not spin around. This means that the state of the top three bits of B is erased - if you do not know this, you cannot restore B.
Example:
10101101 << 3 Turns: 10101101 ^---^ Into: 01101000 ^---^
The top three bits are lost, and the bottom three are filled with zeros. Deleted data is deleted.
| 0x07 | 0x07 fills the lower three bits (with 111 ), so even if you did not shift, you will erase the lower three bits with 111 , making these bits irrevocable.
Now, if it was XOR'd instead of OR'd, it would be restored with another XOR:
A ^ same-value can cancel with another A ^ same-value , because ((A ^ B) ^ B) == A
A | same-value A | same-value cannot be undone with another A | same-value A | same-value
A | same-value A | same-value also cannot cancel with AND: A & same-value
But the shift will still cause problems, even if it was XOR'd (which is not the case).
Jamin gray
source share