Estimate how many bytes this transaction will be by countng inputs
        and outputs.
        Formula taken from: http://bitcoin.stackexchange.com/a/3011/18150
10709
def estimate_size(self):
        
        # if there are no outs use 1 (because the change will be an out)
        outs = len(self.outs) or 1
        return outs * 34 + 148 * len(self.ins) + 10
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
422161
def calculate_size(name, timeout):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += LONG_SIZE_IN_BYTES
    return data_size
397689
int guessPayloadLength() {
    int length = 0;
    // Total guess at average size of stream entry
    try {
      List<Object> payload = getBodyList();
      length = payload.size() * 40;
    }
    catch (UnsupportedEncodingException e) {
      // No FFDC code needed
      // hmm... how do we figure out a reasonable length
    }
    return length;
  }
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;
}
1371493
function ( n, buffer, bytes ) {
                var s = ( n % k ) * slen
                    // how many bytes to read/consume from the input buffer [1 to 4]
                    , rbytes = bytes >>> 0 ? abs( bytes ) % 5 : ibytes
                    , blen = buffer.length - rbytes
                    , bruint = null
                    , sum = 0
                    , b = 0
                    ;
                /*
                 * NOTE: js is not capable to handle integers larger than ~2^53,
                 * when the sum exceeds this limit, we expect to get get biased
                 * results, or in other words, more collisions. It will happens
                 * when we are using large primes as range, or with long buffer
                 * in input. If sum === sum + 1, we could break the for cycle.
                 */
                if ( rbytes === 1 ) {
                    // use [] notation when reading input, 1 byte at the time.
                    if ( ibytes === 1 ) {
                        // read input and seed 1 byte at the time
                        for ( ; b <= blen && s <= rlen; ++b, ++s )
                            sum += buffer[ b ] * result[ s ];
                        return sum % prange;
                    }
                    for ( ; b <= blen && s <= rlen; ++b, s += ibytes )
                        sum += buffer[ b ] * result[ ruint ]( s );
                    return sum % prange;
                }
                // build string for read method (16, 24 or 32 bits unsigned integers)
                bruint =  bruint = 'readUInt' + ( rbytes << 3 ) + 'BE';
                for ( ; b <= blen && s <= rlen; b += rbytes, s += ibytes ) {
                    sum += buffer[ bruint ]( b ) * result[ ruint ]( s );
                    sum %= prange;
                }
                return sum;
            }
1103412
function bnBitCount() {
  var this_array = this.array;
  var r = 0, x = this.s&BI_DM;
  for(var i = 0; i < this.t; ++i) r += cbit(this_array[i]^x);
  return r;
}
663204
def read_octet(self):
        """"""
        self.bitcount = self.bits = 0
        return unpack('B', self.input.read(1))[0]
122943
private int calculateChecksum() {
        long sum = 0;
        for (int i = 0; i < this.headers.capacity() - 1; i += 2) {
            if (i != 10) {
                sum += this.headers.getUnsignedShort(i);
            }
        }

        while (sum >> 16 != 0) {
            sum = (sum & 0xffff) + (sum >> 16);
        }

        return (int) ~sum & 0xFFFF;
    }
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];
    }
258225
def calculate_input(self, buffer):
        
        if TriggerMode.ABBREVIATION in self.modes and self.backspace:
            if self._should_trigger_abbreviation(buffer):
                if self.immediate:
                    return len(self._get_trigger_abbreviation(buffer))
                else:
                    return len(self._get_trigger_abbreviation(buffer)) + 1

        if self.parent is not None:
            return self.parent.calculate_input(buffer)

        return 0
970184
def bits_in(length, keyspace):
    
    keyspace = len(keyspace)
    length_per_cycle = 64
    if length > length_per_cycle:
        bits = 0
        length_processed = 0
        cycles = ceil(length / length_per_cycle)
        for _ in range(int(cycles)):
            if length_processed + length_per_cycle > length:
                length_per_cycle = length - length_processed
            bits += calc_bits_in(length_per_cycle, keyspace)
            length_processed += length_per_cycle
    else:
        bits = calc_bits_in(length, keyspace)
    return float(abs(bits))
260198
def bytes_to_long(bytesdata: bytes) -> int:
    
    assert len(bytesdata) == 8
    return sum((b << (k * 8) for k, b in enumerate(bytesdata)))
75300
def calculate_size(uuid, address, interrupt):
    
    data_size = 0
    data_size += calculate_size_str(uuid)
    data_size += calculate_size_address(address)
    data_size += BOOLEAN_SIZE_IN_BYTES
    return data_size
77067
public static int getIntFromBytes(byte[] bytes,
                                      int    offset,
                                      int    byteCount)
    {
        int value = 0;

        switch (byteCount)
        {
            case 4: value |= ( bytes[offset + 3] & 0xFF);
            case 3: value |= ((bytes[offset + 2] & 0xFF) << 8);
            case 2: value |= ((bytes[offset + 1] & 0xFF) << 16);
            case 1: value |= ((bytes[offset + 0] & 0xFF) << 24);
                    value = value >> ((4 - byteCount) * 8);
                break;
            default:
                final String msg = "byteCount is not between 1 and 4";
                IllegalArgumentException iae = new IllegalArgumentException(msg);
                FFDCFilter.processException(
                    iae,
                    "com.ibm.ws.Transaction.JTA.Util.getIntFromBytes",
                    "553");
                throw iae;
        }

        return value;
    }
460733
def fmt_bytes(bytes, precision=2):
    
    UNITS = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB']

    if bytes == 0:
        return '0 bytes'

    log = math.floor(math.log(bytes, 1000))

    return "%.*f %s" % (precision,
                       bytes / math.pow(1000, log),
                       UNITS[int(log)])
189741
def sizeof_fmt(num):
    
    units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB']
    decimals = [0, 0, 1, 2, 2, 2]
    if num > 1:
        exponent = min(int(log(num, 1024)), len(units) - 1)
        quotient = float(num) / 1024 ** exponent
        unit = units[exponent]
        num_decimals = decimals[exponent]
        format_string = '{0:.%sf} {1}' % (num_decimals)
        return format_string.format(quotient, unit)
    if num == 0:
        return '0 bytes'
    if num == 1:
        return '1 byte'