Decimal to Binary
var decimal = 123;
var remainder;
var binary = [];
while (decimal > 0) {
remainder = decimal % 2;
decimal = (decimal / 2) >> 0;
binary.unshift(remainder);
}
console.log(binary.join(""));
Written by Béla Varga
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Related Tags
#javascript
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#