Convert decimal to binary [closed]

-2

I'm stuck in a programming logic problem, where you need to create a JavaScript function that takes a decimal and converts it to binary.

    
asked by anonymous 23.08.2018 / 01:47

1 answer

0

DEC2BIN converts a decimal number to a binary number

function dec2bin(dec){
    return (dec >>> 0).toString(2);
}


console.log(dec2bin(256));

console.log(dec2bin(1024));
 Resultado  Formula 
 1010       = DEC2BIN(10)   
 01010      = DEC2BIN(10, 5)    
 1111100000 = DEC2BIN(-32)
  

If you want to do a padding or see other options click here

Source and more options

strong>

    
23.08.2018 / 01:56