I am writing an algorithm in a limited language where the bitwise operators at my disposal are
AND
:&
OR
:|
XOR
:^
SRL
:<<
(shift left)SLL
:>>
(shift right)
I realized I need to be able to take the bitwise complement of an integer, commonly denoted ~x
in other languages.
Could I somehow express ~x
, using only the {&, |, ^, <<, >>}
operators?
I would try to just implement this operator in the language’s compiler, but it seems like a very challenging task. I would much rather do some dirty hack to express NOT x
without ~
.