Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function decimalToBinary(inputNum) {
- let binary = [];
- while (inputNum > 0) {
- if (inputNum % 2 === 1) {
- binary.splice(0,0,1);
- inputNum = (inputNum - 1) / 2;
- } else {
- binary.splice(0,0,0);
- inputNum /= 2;
- }
- }
- binary = binary.join('');
- console.log(binary);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement