bp99
bp99

Reputation: 348

Express bitwise negation (`NOT`, bitwise complement) using other bitwise operations?

I am writing an algorithm in a limited language where the bitwise operators at my disposal are

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 ~.

Upvotes: 1

Views: 346

Answers (0)

Related Questions