I have a 64 element JavaScript array that I'm using as a bitmask. Unfortunately, I've run into a problem when converting from a string to binary, and back. This has worked for some other arrays, but what is going on here?
var a = [1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 0, 0, 1, 1, 1, 1,
1, 1, 0, 0, 1, 1, 1, 1,
1, 1, 0, 0, 0, 0, 1, 1,
1, 1, 0, 0, 0, 0, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1];
var str1 = a.join('');
//-> '1111111111111111110011111100111111000011110000111111111111111111'
var str2 = parseInt(str1, 2).toString(2);
//-> '1111111111111111110011111100111111000011110001000000000000000000'
str1 === str2 //-> false
I would expect str2
to be the same as str1
, which is not the case.