Skip to content

Latest commit

 

History

History
15 lines (14 loc) · 346 Bytes

decimal_to_binary.md

File metadata and controls

15 lines (14 loc) · 346 Bytes

Decimal to binary

function decToBin(num){
    if(num >= 1){
        return decToBin(Math.floor(num/2)) + (num % 2);
    }
    // we return a string with leading 0
    // so the function will concatenate the
    // output of the function and return the
    // correct result i.e 1 = 01
    // !!!! 0 = 0, not 00!!!!
    return '0';
}