I have this code // Fiddle : https://jsfiddle.net/7buscnhw/
// Word to bits func
function dec2bin(dec) {
return (dec >>> 0).toString(2);
}
// binary to bit array
function bin2array(bin) {
let Bitarr = []
for(let i = 0; i < bin.length; ++i)
Bitarr[i] = (bin >> i) & 1;
return Bitarr;
}
R24011 = dec2bin(10);
Bits = bin2array(R24011);
msg = {
R24011: R24011,
BitArray: Bits
}
console.log(msg)
It correctly outputs 1010 for Ten in binary, but when I push it to an array I get [0,1,0,0]
I'm sure it'll be something stupid but I cant figure out what I've done wrong.
bin2array(dec2bin(10))