Nodejs Number to Binary Convert bin()

Here you can find the source of bin()

Method Source Code

Number.prototype.bin = function () { 
  var shifted = this
    , result = '';

  for (var flag = 0; flag < 32; flag++) {
    result += String(shifted >>> 31);
    shifted <<= 1;/*from   ww w  . j  a v a2 s  .co m*/
  }
  return result;
}

Related

  1. bin32()
    Number.prototype.bin32 = function () {
      var result = this.toString(2);
      while (result.length < 32) {
        result = '0' + result;
      return result;
    var reverseBits = function (n) {
      return parseInt(n.bin32().split('').reverse().join(''), 2);
    ...