← Back to challenges

Bitwise Logical Negation

JavaScriptHardlogicbit_operations

Instructions

Given a number (positive, negative, or 0), return the logical negation (as a 1 or 0) of that number. Do so using only bitwise operators:

~, &, |, ^, >>, <<, +

Any of these characters / constructs are not allowed:

if, do, while, for, switch, -, ?, :, !, ||, &&, <, >, == , [,], functions

Examples

bitwiseLogicalNegation(1) ➞ 0

bitwiseLogicalNegation(5) ➞ 0

bitwiseLogicalNegation(0) ➞ 1

bitwiseLogicalNegation(3) ➞ 0

Notes

Use as few operators as possible for more of a challenge.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.