convert an integer to a byte array
@param {Integer} num
@return {Array} bytes
505187
function intToBytes(num) {
	var bytes = [];

	for(var i=7 ; i>=0 ; --i) {
		bytes[i] = num & (255);
		num = num >> 8;
	}

	return bytes;
}
1023583
private function readAndHashBytes($num)
    {
        $bytes = $this->stream->read($num);
        hash_update($this->hashContext, $bytes);
        return $bytes;
    }
584721
public static byte[] integer_to_bytes(int i) {
		final byte[] b = new byte[4];
		b[0] = (byte) (i & 0xff);
		i >>= 8;
		b[1] = (byte) (i & 0xff);
		i >>= 8;
		b[2] = (byte) (i & 0xff);
		i >>= 8;
		b[3] = (byte) (i & 0xff);
		return b;
	}
278681
function (num) {
      switch (typeof num) {
        case 'number':
          return num;
        case 'string':
          if (!isNaN(num)) {
            return num.indexOf('.') > -1 ? parseFloat(num) : parseInt(num, 10);
          }
      }

      return num;
    }
1119560
def convert_bytes_to_ints(in_bytes, num):
    """"""
    out_arr = []
    for i in range(len(in_bytes)//num):
        val = in_bytes[i * num:i * num + num]
        unpacked = struct.unpack(mmtf.utils.constants.NUM_DICT[num], val)
        out_arr.append(unpacked[0])
    return out_arr
347012
function readBytes(arr, n) {
		var i, ret = [];
		for (i = 0; i < n; i += 1) {
			ret.push(arr.shift());
		}

		return ret;
	}
663759
public static byte[] toBytes(long value, int length) {
        if (length <= 0) return new byte[0];
        if (length > 8) length = 8;
        byte[] out = new byte[length];
        for (int i = length - 1; i >= 0; i--){
            out[i] = (byte)(value & 0xFFL);
            value = value >> 8;
        }
        return out;
    }
120437
function encodeArray_NUM_RAW( encoder, data, n_type ) {

	//
	// RAW Numeric Array (NUM_RAW)
	//
	// ....  ...    .   +   Data Length
	// 0101 [TYPE] [LN]    [16bit/32bit]
	//

	encoder.counters.arr_num_raw+=1;
	encoder.log(LOG.ARR, "array.numeric.raw, len="+data.length+
		", type="+_NUMTYPE[n_type]+" ("+n_type+")");

	if (data.length < UINT16_MAX) { // 16-bit length prefix
		encoder.stream8.write( pack1b( ARR_OP.NUM_RAW | NUMTYPE_LN.UINT16 | (n_type << 1) ) );
		encoder.stream16.write( pack2b( data.length, false ) );
		encoder.counters.arr_hdr+=3;
	} else { // 32-bit length prefix
		encoder.stream8.write( pack1b( ARR_OP.NUM_RAW | NUMTYPE_LN.UINT32 | (n_type << 1) ) );
		encoder.stream32.write( pack4b( data.length, false ) );
		encoder.counters.arr_hdr+=5;
	}

	// Encode the short array
	pickStream( encoder, n_type )
		.write( packTypedArray( convertArray( data, n_type ) ) );

}
681403
function transferNumber(value, num) {
    var str = value.toString(2);
    var ary = [];
    var end = str.length;
    var start;

    for (var i = 1; i < num + 1; i++) {
      start = -7 * i;
      ary.push(str.slice(start, end));
      end = start;
    }

    ary.forEach(function(val, idx, target) {
      val = parseInt(val, 2);
      val > 0 || (val = 0);
      target[idx] = val;
    });
    return ary;
  }
916693
def bytes(num=10)
      num = [[2048, num.to_i].min , 0].max
      numbers = []

      response = REXML::Document.new( open("https://www.fourmilab.ch/cgi-bin/Hotbits?fmt=xml&nbytes=#{num}"))
      status = REXML::XPath.first( response, "//status")
      case status.attributes['result'].to_i 
      when 200
       data = REXML::XPath.first( response, "//random-data" ).text.split
       data.each{|byte| numbers << byte.hex}
      when 503
       raise StandardError.new "#{status.text}"
      end

      numbers
    end
895675
function (num) {
  var arr = [];

  if (num === 0) return new Buffer([0]);

  // Break up num into groups of 7-bit values
  while (num) {
    arr.unshift(num & (127));
    num >>= 7;
  }

  // Flip MSB of all 7-bit values except the last one
  arr = _.map(_.initial(arr), function (val, i) {
    return val + 128;
  }).concat(_.last(arr));

  return new Buffer(arr);
}
1133447
def convert_number(num)
    # Integer in the range 0..2**16-1
    if ((num =~ /^\d+$/) && (num.to_i <= 65535))
      return [@ptg['ptgInt'], num.to_i].pack("Cv")
    else  # A float
      num = [num.to_f].pack("d")
      num.reverse! if @byte_order
      return [@ptg['ptgNum']].pack("C") + num
    end
  end
1213290
protected static function getRandomBytes($num = 16)
    {
        static $which = null;
        if ($which === null) {
            if (\function_exists('\\random_bytes') && \version_compare(\phpversion(), '7.0.0', '>=')) {
                $which = 'php7';
            } elseif (\function_exists('\\openssl_random_pseudo_bytes')) {
                $which = 'openssl';
            } elseif (\function_exists('\\mcrypt_create_iv')) {
                $which = 'mcrypt';
            } elseif (\is_readable('/dev/urandom')) {
                $which = 'urandom';
            } else {
                $which = 'fallback';
            }
        }

        if ($num < 1 || $num > PHP_INT_MAX) {
            return false;
        }

        // Now let's get some random bytes
        switch ($which) {
            case 'php7':
                return \random_bytes($num);
            case 'mcrypt':
                return \mcrypt_create_iv($num, MCRYPT_DEV_URANDOM);
            case 'openssl';
                return \openssl_random_pseudo_bytes($num);
            case 'urandom':
                $fp = \fopen('/dev/urandom', 'rb');
                \stream_set_read_buffer($fp, 0);
                $bytes = \fread($fp, $num);
                \fclose($fp);
                return $bytes;
            default:
                // I really hope this is never necessary
                $bytes = '';
                for ($i = 0; $i < $num; ++$i) {
                    $bytes .= \chr(\mt_rand(0, 255) ^ \rand(0, 255));
                }

                $xorbuf = \sha1(\json_encode($_SERVER), true);
                while (self::safeStrlen($xorbuf) < $num) {
                    $xorbuf .= \sha1(
                        \uniqid(
                            \md5(
                                \microtime(true) . \lcg_value()
                            ),
                            true
                        ),
                        true
                    );
                }
                for ($i = 0; $i < $num; ++$i) {
                    $bytes[$i] ^= $xorbuf[$i];
                }

                return $bytes;
        }
    }
1052532
public static byte[] intToNetworkByteOrder(int num, int count) {
        byte[] buf = new byte[count];
        intToNetworkByteOrder(num, buf, 0, count);
        
        return buf;
    }
821517
private function encodeNumber($num)
    {
        $encodeString = '';

        while ($num >= 0x20) {
            $nextValue = (0x20 | ($num & 0x1f)) + 63;
            $encodeString .= chr($nextValue);
            $num >>= 5;
        }
        $finalValue = $num + 63;
        $encodeString .= chr($finalValue);
        return $encodeString;
    }
307638
function(bytes) {
      for (var hex = [], i = 0; i < bytes.length; i++) {
        hex.push((bytes[i] >>> 4).toString(16));
        hex.push((bytes[i] & 0xF).toString(16));
      }
      return hex.join('');
    }
694886
function getBytesWithUnit(bytes) {
        if (isNaN(bytes)) {
            return;
        }
        var units = [ ' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB' ];
        var amountOf2s = Math.floor(Math.log(+bytes) / Math.log(2));
        if (amountOf2s < 1) {
            amountOf2s = 0;
        }
        var i = Math.floor(amountOf2s / 10);
        bytes = +bytes / Math.pow(2, 10 * i);


        if (bytes.toString().length > bytes.toFixed(2).toString().length) {
            bytes = bytes.toFixed(2);
        }
        return bytes + units[i];
    }