1function dec2Bin(dec)
2{
3 if(dec >= 0) {
4 return dec.toString(2);
5 }
6 else {
7 /* Here you could represent the number in 2s compliment but this is not what
8 JS uses as its not sure how many bits are in your number range. There are
9 some suggestions https://stackoverflow.com/questions/10936600/javascript-decimal-to-binary-64-bit
10 */
11 return (~dec).toString(2);
12 }
13}
14