i am trying to convert a decimal number into a binary number and i wrote a function in c++ that do this work and it worked fine , but when i wrote the same function in Javascript it didn't work out and printed a false value like "11101111111111" something like that. can anyone tell me what's wrong with this function ?
var decToBinary=function() {
var n=16,s="";
while(n) {
if(n % 2 == 0)
s += "0";
else
s += "1";
n /= 2;
}
s.reverse();
return s;
}