Convert decimal to binary [closed]

closed . This question needs to be more objective and is not currently accepting answers.

want to improve this question? update the question to focus on just one problem when edit it .

Closed 2 years ago .

improve this question

I'm stuck in a programming logic problem, where you have to create a JavaScript function that receives any decimal and converts to binary.

Author: Pedro Castro, 2018-08-22

1 answers

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

Font and more options

 1
Author: Leo Caracciolo, 2018-08-23 00:20:52