Skip to main content
added 12 characters in body
Source Link

An actual solution that logic can be implemented by any programming language:

If you sure it is positive only:

var aout = 0;
var n = 12; // your input
var m = 1;
while(n) {
    aout = aout + n%2*m;n%2 * m;
    n = Math.floor(n/2);
    m = m*10;m * 10;
}

console.log(n, ':', aout) // 12 : 1100

If can negative or positive -

(n >>> 0).toString(2)

An actual solution that logic can be implemented by any programming language:

If you sure it is positive only:

var a = 0;
var n = 12; // your input
var m = 1;
while(n) {
    a = a + n%2*m;
    n = Math.floor(n/2);
    m = m*10;
}

console.log(n, ':', a) // 12 : 1100

If can negative or positive -

(n >>> 0).toString(2)

An actual solution that logic can be implemented by any programming language:

If you sure it is positive only:

var out = 0;
var n = 12; // your input
var m = 1;
while(n) {
    out = out + n%2 * m;
    n = Math.floor(n/2);
    m = m * 10;
}

console.log(n, ':', out) // 12 : 1100

If can negative or positive -

(n >>> 0).toString(2)
Mod Removes Wiki by Makyen
Post Made Community Wiki by Makyen
added 111 characters in body
Source Link

An actual solution that logic can be implemented by any programming language:

If you sure it is positive only:

var a = 0;
var n = 12; // your input
var m = 1;
while(n) {
    a = a + n%2*m;
    n = Math.floor(n/2);
    m = m*10;
}

console.log(n, ':', a) // 12 : 1100

If can negative or positive -

(n >>> 0).toString(2)

An actual solution that logic can be implemented by any programming language:

var a = 0;
var n = 12; // your input
var m = 1;
while(n) {
    a = a + n%2*m;
    n = Math.floor(n/2);
    m = m*10;
}

console.log(n, ':', a) // 12 : 1100

An actual solution that logic can be implemented by any programming language:

If you sure it is positive only:

var a = 0;
var n = 12; // your input
var m = 1;
while(n) {
    a = a + n%2*m;
    n = Math.floor(n/2);
    m = m*10;
}

console.log(n, ':', a) // 12 : 1100

If can negative or positive -

(n >>> 0).toString(2)
Source Link

An actual solution that logic can be implemented by any programming language:

var a = 0;
var n = 12; // your input
var m = 1;
while(n) {
    a = a + n%2*m;
    n = Math.floor(n/2);
    m = m*10;
}

console.log(n, ':', a) // 12 : 1100