let inverted_number = ~4; // 3
let inverted_number = ~4; alert(inverted_number); //-5
00000000000000000000000000000100
11111111111111111111111111111011
let val = 4 val = val.toString(2).replace(/1|0/g, _ => !+_ ? 1 : 0 ) alert(val)
function inv(n) { let p = 1; while (p <= n) p *= 2; return ~n & (p - 1); } alert(inv(4));