I'm trying to convert binary unsigned number to two's complement with javascript:
function bin_input_to_num(input) // 2 bit, input is string
{
return ~Number('0b' + input) + '0b01'; // using ES6
}
console.log(bin_input_to_num('11')); // actual: -3, expected: -1
I'm not sure what I'm missing.
(edit: I have carefully read through the marked possible duplicate question and answers, and it doesn't resolve my issue here)