Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Convert Number To Binary


function convertToBinary(x) {
    let bin = 0;
    let rem, i = 1;
    /*rem is the remaining Number, i is the current step total, bin is the binary answer*/
    while (x != 0) {
        rem = x % 2;
             x = parseInt(x / 2);
        bin = bin + rem * i;
        i = i * 10;
    }
return bin;
}

console.log(convertToBinary(4))
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Convert #Number #To #Binary
ADD COMMENT
Topic
Name
4+6 =