\
    Packs eight bits into one byte.

    If the length of the iterable is not a multiple of eight, ``0x0`` is used
    to fill-up the missing values.
516305
def _pack_bits_into_byte(iterable):
    
    return (reduce(lambda x, y: (x << 1) + y, e)
            for e in zip_longest(*[iter(iterable)] * 8, fillvalue=0x0))
947151
def int_to_binary(value)
      # Note: nbytes is actually an exponent.  number of bytes = 2**nbytes.
      nbytes = 0
      nbytes = 1  if value > 0xFF # 1 byte unsigned integer
      nbytes += 1 if value > 0xFFFF # 4 byte unsigned integer
      nbytes += 1 if value > 0xFFFFFFFF # 8 byte unsigned integer
      nbytes += 1 if value > 0x7FFFFFFFFFFFFFFF # 8 byte unsigned integer, stored in lower half of 16 bytes
      nbytes = 3  if value < 0 # signed integers always stored in 8 bytes

      Binary.type_bytes(0b0001, nbytes) <<
        if nbytes < 4
          [value].pack(["C", "n", "N", "q>"][nbytes])
        else # nbytes == 4
          [0,value].pack("Q>Q>")
        end
    end
703894
def _decompose_bytes_to_bit_arr(arr):
    
    bit_arr = []
    for idx in range(len(arr)):
        for i in reversed(range(8)):
            bit_arr.append((arr[idx] >> i) & (1 << 0))
    return bit_arr
949798
def pack_bits( longbits ):
    """"""
    byte = longbits & (0x0101010101010101)
    byte = (byte | (byte>>7)) & (0x0003000300030003)
    byte = (byte | (byte>>14)) & (0x0000000f0000000f)
    byte = (byte | (byte>>28)) & (0x00000000000000ff)
    return byte
1281444
def readsleb128(buff):
    
    result = 0
    shift = 0

    for x in range(0, 5):
        cur = get_byte(buff)
        result |= (cur & 0x7f) << shift
        shift += 7

        if not cur & 0x80:
            bit_left = max(32 - shift, 0)
            result = result << bit_left
            if result > 0x7fffffff:
                result = (0x7fffffff & result) - 0x80000000
            result = result >> bit_left
            break

    return result
1265729
def _long_to_bytes(n, length, byteorder):
    
    if byteorder == 'little':
        indexes = range(length)
    else:
        indexes = reversed(range(length))
    return bytearray((n >> i * 8) & 0xff for i in indexes)
210589
function (bytes) {
    var out = [], i, tmp=0;
    for (i=0; i<bytes.length; i++) {
      tmp = tmp << 8 | bytes[i];
      if ((i&3) === 3) {
        out.push(tmp);
        tmp = 0;
      }
    }
    if (i&3) {
      out.push(sjcl.bitArray.partial(8*(i&3), tmp));
    }
    return out;
  }
922997
function unpack (x, m) {
        for (var i = 0; i < KEY_SIZE; i += 2)
            x[i / 2] = m[i] & 0xFF | ((m[i + 1] & 0xFF) << 8);
    }
505442
def pack_iterable(messages):
    ''''''
    # [ 4-byte body size ]
    # [ 4-byte num messages ]
    # [ 4-byte message #1 size ][ N-byte binary data ]
    #      ... (repeated <num_messages> times)
    return pack_string(
        struct.pack('>l', len(messages)) +
        ''.join(map(pack_string, messages)))
272990
def utf8_char_length_in_bytes(first_byte)
      if first_byte.hex < 'C0'.hex
        1
      elsif first_byte.hex < 'DF'.hex
        2
      elsif first_byte.hex < 'EF'.hex
        3
      else
        4
      end
    end
657125
function bytesToWords(input) {
  var i;
  var output = [];
  output[(input.length >> 2) - 1] = undefined;
  for (i = 0; i < output.length; i += 1) {
    output[i] = 0;
  }
  var length8 = input.length * 8;
  for (i = 0; i < length8; i += 8) {
    output[i >> 5] |= (input[(i / 8)] & 0xFF) << (i % 32);
  }

  return output;
}
284514
def inttoLEB128(intinput):
    '''
    
    '''

    binstr = str(bin(intinput)) \
             .lstrip("0b").replace("b","").replace("L","") \
             .replace("'","").replace('"',"")
    if len(binstr) % 7:
        binstr = binstr.zfill(len(binstr) + 7 - (len(binstr) % 7))
    bytelist = ""
    for i in range(len(binstr) // 7):
        if i < ((len(binstr) // 7) - 1):
            pad = "1"
        else:
            pad = "0"
        currbyte = binstr[(len(binstr) - (7*i + 7)):(len(binstr) - (7*i))]
        currbyte = pad + currbyte
        currbyte = dechex(int(currbyte,2))
        # assert len(currbyte) == 2
        bytelist = bytelist + currbyte
    return bytelist
420903
function zip_send_bits(
  value,	// value to send
  length) {	// number of bits
  /* If not enough room in bi_buf, use (valid) bits from bi_buf and
   * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
   * unused bits in value.
   */
  if (zip_bi_valid > zip_Buf_size - length) {
    zip_bi_buf |= (value << zip_bi_valid);
    zip_put_short(zip_bi_buf);
    zip_bi_buf = (value >> (zip_Buf_size - zip_bi_valid));
    zip_bi_valid += length - zip_Buf_size;
  } else {
    zip_bi_buf |= value << zip_bi_valid;
    zip_bi_valid += length;
  }
}
1058291
def num2bytes(x, bytes):
    
    if not isinstance(x, int):  # If it is another "thing", just return ZEROs
        return tuple([0] * bytes)

    x = x & ((2 << (bytes * 8)) - 1)  # mask the initial value
    result = ()

    for i in range(bytes):
        result += (x & 0xFF,)
        x >>= 8

    return result
1163630
def _as_chunk(self):
        

        extra_bits = int_from_bytes(self.contents[0:1])
        bit_string = '{0:b}'.format(int_from_bytes(self.contents[1:]))

        # Ensure we have leading zeros since these chunks may be concatenated together
        mod_bit_len = len(bit_string) % 8
        if mod_bit_len != 0:
            bit_string = ('0' * (8 - mod_bit_len)) + bit_string

        if extra_bits > 0:
            return bit_string[0:0 - extra_bits]

        return bit_string
1236011
def _double_as_bytes(dval):
    ""
    tmp = list(struct.unpack('8B',struct.pack('d', dval)))
    if not _big_endian:
        tmp.reverse()
    return tmp
1053213
def pack(self, remaining_size):
        """"""
        arguments_count, payload = self.pack_data(remaining_size - self.header_size)
        payload_length = len(payload)

        # align payload length to multiple of 8
        if payload_length % 8 != 0:
            payload += b"\x00" * (8 - payload_length % 8)

        self.header = PartHeader(self.kind, self.attribute, arguments_count, self.bigargumentcount,
                                 payload_length, remaining_size)
        hdr = self.header_struct.pack(*self.header)
        if pyhdb.tracing:
            self.trace_header = humanhexlify(hdr, 30)
            self.trace_payload = humanhexlify(payload, 30)
        return hdr + payload