I have a number 5. How to get a “boolean bit array” like the array below?
array = [false, false, true, false, true]; // 00101
(Need reserve the first two false)
Advertisement
Answer
This will do:
("0000" + Math.abs(number).toString(2)).slice(-5).split("").map(Number).map(Boolean)