Returns the binary representation of the var-length string.
161852
def encode_string(string)
      raise ArgumentError, "String must be present" if !string
      encode_varint(string.bytesize) + BTC::Data.ensure_binary_encoding(string)
    end
798962
def VarintEncode(value):
  """"""
  result = b""
  if value < 0:
    raise ValueError("Varint can not encode a negative number.")

  bits = value & 0x7f
  value >>= 7

  while value:
    result += HIGH_CHR_MAP[bits]
    bits = value & 0x7f
    value >>= 7

  result += CHR_MAP[bits]

  return result
1360177
public static long binValueOf(final String binaryStr) {
    if (Strings.isEmpty(binaryStr)) { return 0; }
    long value = 0;
    long height = 1;

    for (int i = binaryStr.length() - 1; i >= 0; i--) {
      if ('1' == binaryStr.charAt(i)) {
        value += height;
      }
      height *= 2;
    }
    return value;
  }
841565
function toBinaryString(arr) {
                var str = '';
                for (var i = 0; i < arr.length; i++) {
                    var obj = (arr[i] >>> 0).toString(2);
                    str += '00000000000000000000000000000000'.substr(obj.length) + obj;
                }
                return str;
            }
67339
public static long getVarInt(byte[] varInt) {
	long result=0;
	if (varInt.length==0) {
		 return result;
	}
	int unsignedByte=varInt[0] & 0xFF;
	if (unsignedByte<0xFD) {
		return unsignedByte;
	}
	int intSize=0;
	if (unsignedByte==0xFD) { 
		intSize=3;
	}
	else if (unsignedByte==0xFE) {
		intSize=5;
	}
	else if (unsignedByte==0XFF) {
		intSize=9;
	}
	byte[] rawDataInt=reverseByteArray(Arrays.copyOfRange(varInt, 1, intSize));
	ByteBuffer byteBuffer = ByteBuffer.wrap(rawDataInt);
	if (intSize==3) {
		 result=byteBuffer.getShort();
	}
	else if (intSize==5) {
		result=byteBuffer.getInt();
	}
	else if (intSize==9) {
		result=byteBuffer.getLong(); // Need to handle sign - available only in JDK8
	}
	return result;
}
1364700
def to_binary_string(obj, encoding=None):
    """"""
    if PY2:
        # Python 2
        if encoding is None:
            return str(obj)
        else:
            return obj.encode(encoding)
    else:
        # Python 3
        return bytes(obj, 'utf-8' if encoding is None else encoding)
616897
private void logBinaryStringInfo(StringBuilder binaryString) {

        encodeInfo += "Binary Length: " + binaryString.length() + "\n";
        encodeInfo += "Binary String: ";

        int nibble = 0;
        for (int i = 0; i < binaryString.length(); i++) {
            switch (i % 4) {
                case 0:
                    if (binaryString.charAt(i) == '1') {
                        nibble += 8;
                    }
                    break;
                case 1:
                    if (binaryString.charAt(i) == '1') {
                        nibble += 4;
                    }
                    break;
                case 2:
                    if (binaryString.charAt(i) == '1') {
                        nibble += 2;
                    }
                    break;
                case 3:
                    if (binaryString.charAt(i) == '1') {
                        nibble += 1;
                    }
                    encodeInfo += Integer.toHexString(nibble);
                    nibble = 0;
                    break;
            }
        }

        if ((binaryString.length() % 4) != 0) {
            encodeInfo += Integer.toHexString(nibble);
        }

        encodeInfo += "\n";
    }
873178
public static final Function<BigDecimal,String> toStr() {
	    return (Function<BigDecimal,String>)((Function)FnNumber.toStr());
    }
813866
def pack_bitstring(length, is_float, value, signed):
    
    if is_float:
        types = {
            32: '>f',
            64: '>d'
        }

        float_type = types[length]
        x = bytearray(struct.pack(float_type, value))
        bitstring = ''.join('{:08b}'.format(b) for b in x)
    else:
        b = '{:0{}b}'.format(int((2<<length )+ value), length)
        bitstring = b[-length:]

    return bitstring
96682
def size_of_varint(value):
    
    value = (value << 1) ^ (value >> 63)
    if value <= 0x7f:
        return 1
    if value <= 0x3fff:
        return 2
    if value <= 0x1fffff:
        return 3
    if value <= 0xfffffff:
        return 4
    if value <= 0x7ffffffff:
        return 5
    if value <= 0x3ffffffffff:
        return 6
    if value <= 0x1ffffffffffff:
        return 7
    if value <= 0xffffffffffffff:
        return 8
    if value <= 0x7fffffffffffffff:
        return 9
    return 10
648092
def to_binary_string(self):
        """"""
        timestamp = datetime_to_timestamp(self.when)
        token = binascii.unhexlify(self.token)
        return struct.pack(self.FORMAT_PREFIX + '{0}s'.format(len(token)),
                           timestamp, len(token), token)
752534
def int_to_var_bytes(x):
    
    if x < 253:
        return intbytes.to_bytes(x, 1)
    elif x < 65536:
        return bytearray([253]) + intbytes.to_bytes(x, 2)[::-1]
    elif x < 4294967296:
        return bytearray([254]) + intbytes.to_bytes(x, 4)[::-1]
    else:
        return bytearray([255]) + intbytes.to_bytes(x, 8)[::-1]
210629
def _VarintEncoder():
  """"""

  def EncodeVarint(write, value):
    bits = value & 0x7f
    value >>= 7
    while value:
      write(six.int2byte(0x80|bits))
      bits = value & 0x7f
      value >>= 7
    return write(six.int2byte(bits))

  return EncodeVarint
509977
def ReadVarString(self, max=sys.maxsize):
        
        length = self.ReadVarInt(max)
        return self.unpack(str(length) + 's', length)
240617
public static final Function<Long,String> toStr() {
        return (Function<Long,String>)((Function)FnNumber.toStr());
    }
412245
def _str(val):
    
    if str == bytes:
        if isinstance(val, str):
            return val
        else:
            return str(val)
    else:
        if isinstance(val, str):
            return val
        else:
            return str(val, 'ascii')
244872
function (bytes) {

    var str = "";
    var code, b1, b2, b3, b4, upper, lower;
    var i = 0;

    while (i < bytes.length) {

        b1 = bytes[i++];

        if (b1 < 0x80) {
            // 1 byte
            code = b1;
        } else if ((b1 >> 5) === 0x06) {
            // 2 bytes
            b2 = bytes[i++];
            code = ((b1 & 0x1f) << 6) | (b2 & 0x3f);
        } else if ((b1 >> 4) === 0x0e) {
            // 3 bytes
            b2 = bytes[i++];
            b3 = bytes[i++];
            code = ((b1 & 0x0f) << 12) | ((b2 & 0x3f) << 6) | (b3 & 0x3f);
        } else {
            // 4 bytes
            b2 = bytes[i++];
            b3 = bytes[i++];
            b4 = bytes[i++];
            code = ((b1 & 0x07) << 18) | ((b2 & 0x3f) << 12) | ((b3 & 0x3f) << 6) | (b4 & 0x3f);
        }

        if (code < 0x10000) {
            str += String.fromCharCode(code);
        } else {
            // surrogate pair
            code -= 0x10000;
            upper = (0xD800 | (code >> 10));
            lower = (0xDC00 | (code & 0x3FF));
            str += String.fromCharCode(upper, lower);
        }
    }

    return str;
}