Write a function that prints out the binary form of an int
function dec2bin(dec){
return (dec >>> 0).toString(2);
}
https://stackoverflow.com/questions/9939760/how-do-i-convert-an-integer-to-binary-in-javascript
You can use Number.toString(2) function, but it has some problems when representing negative numbers. For example, (-1).toString(2) output is "-1". To fix this issue, you can use the unsigned right shift bitwise operator (>>>) to coerce your number to an unsigned integer. If you run (-1 >>> 0).toString(2) you will shift your number 0 bits to the right, which doesn't change the number itself but it will be represented as an unsigned integer. The code above will output "11111111111111111111111111111111" correctly.
-3 >>> 0 (right logical shift) coerces its arguments to unsigned integers, which is why you get the 32-bit two's complement representation of -3.
Note 1
this answer expects a Number as argument, so convert your accordingly.
Note 2
the result is the a string without leading zeros, so zero pad accordingly.