Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let toNegative = function(n)
- {
- // take the binary complement
- n = ~n;
- // add 1
- n += 1;
- // return final result of -n
- return n
- }
- let a = parseInt(prompt("Enter an integer"));
- let na = toNegative(a);
- console.log(`n: ${a}`);
- console.log(`n: ${na}`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement