Send a string of bits

@param bitString Bits (e.g. 000000000001010100010001)
961914
public void send(final String bitString) {
        BitSet bitSet = new BitSet(bitString.length());
        for (int i = 0; i < bitString.length(); i++) {
            if (bitString.charAt(i) == '1') {
                bitSet.set(i);
            }
        }
        send(bitSet, bitString.length());
    }
919407
public synchronized void write(final Bits bits) throws IOException {
    Bits newRemainder = this.remainder.concatenate(bits);
    final int newRemainingBits = newRemainder.bitLength % 8;
    int bitsToWrite = newRemainder.bitLength - newRemainingBits;
    if (bitsToWrite > 0) {
      assert (0 == bitsToWrite % 8);
      final Bits toWrite = newRemainder.range(0, bitsToWrite);
      this.inner.write(toWrite.getBytes());
      newRemainder = newRemainder.range(bitsToWrite);
    }
    this.remainder = newRemainder;
    this.totalBitsWritten += bits.bitLength;
  }
1069208
public static int writeString(final BitOutput bitOutput, final int lengthSize, final String value,
                                  final String charsetName)
            throws IOException {
        return writeBytes(bitOutput, lengthSize, Byte.SIZE, value.getBytes(charsetName));
    }
170172
static protected int getPadBits(
        int bitString)
    {
        int val;

        if (bitString == 0)
        {
            return 7;
        }

        if (bitString > 255)
        {
            val = ((bitString >> 8) & 0xFF);
        }
        else
        {
            val = (bitString & 0xFF);
        }

        int bits = 1;

        while (((val <<= 1) & 0xFF) != 0)
        {
            bits++;
        }

        return 8 - bits;
    }
822222
private String formatNumStr(int bits, String str) {

        String ret;
        String[] inputStr = str.split("\\.");
        if (str.trim().equals("")) {
            ret = String.format("%" + bits + "s", "");
        } else if (str.length() <= bits) {
            ret = String.format("%1$" + bits + "s", str);
        } else if (inputStr[0].length() > bits) {
            ret = String.format("%" + bits + "s", str);
        } else {
            int decimalLength = bits - inputStr[0].length() - 1;
            decimalLength = decimalLength < 0 ? 0 : decimalLength;
            ret = org.agmip.common.Functions.round(str, decimalLength);
        }

        return ret;
    }
1273566
public void write(final byte[] bText)
		throws EncodingException
	{

		writeFillBits();

		int l = bText.length;
		for (int i = 0; i < l; i++) {
			write(0xFF & bText[i]);
		}
	}
1210753
public void addString(String s) throws IOException
    {
        if (s==null)
        {
            addInt(0xFFFF);
            return;
        }

        if (_byteWriter==null)
            _byteWriter=new ByteArrayISO8859Writer(_buf);

        int p=_bytes+2;
        _byteWriter.setLength(p);
        _byteWriter.write(s);
        int l=_byteWriter.size()-p;

        addInt(l);
        _bytes+=l;
        _buf[_bytes++]=(byte)0;
    }
1256181
public static int writeString(final DataOutput out, final String s) throws IOException {

		int length = 0;

		if (s == null) {
			out.writeBoolean(false);
		} else {
			out.writeBoolean(true);
			final ByteBuffer bytes = encode(s);
			length = bytes.limit();
			out.writeInt(length);
			out.write(bytes.array(), 0, length);
		}
		return length;
	}
161852
def encode_string(string)
      raise ArgumentError, "String must be present" if !string
      encode_varint(string.bytesize) + BTC::Data.ensure_binary_encoding(string)
    end
1251572
static String byteToBinaryString(byte b, int limit) {
    final StringBuilder sb = new StringBuilder();
    if (limit > 8) {
      limit = 8;
    }
    for (int i = 0; i < limit; i++) {
      sb.append((char)('0' + (b&1)));
      b>>=1;
    }
    return sb.toString();
  }
1068622
public static Bit valueOf(String bit) throws NumberFormatException {
    final int i = ParseUtil.parseIntBase10(bit);
    if(i != 0 && i != 1) {
      throw new NumberFormatException("Input \"" + bit + "\" must be 0 or 1.");
    }
    return (i > 0) ? TRUE : FALSE;
  }
788800
def write_bits(self, bits):
        
        for bit in bits:
            self._bits.append(bit)

        while len(self._bits) >= 8:
            byte_bits = [self._bits.popleft() for x in six.moves.range(8)]
            byte = bits_to_bytes(byte_bits)
            self._stream.write(byte)
628314
private function doSetBinaryBitsetLeBin($bitset): void
    {
        $size   = \strlen($this->bitset);
        $sizeIn = \strlen($bitset);

        if ($sizeIn < $size) {
            // add "\0" if the given bitset is not long enough
            $bitset .= \str_repeat("\0", $size - $sizeIn);
        } elseif ($sizeIn > $size) {
            if (\ltrim(\substr($bitset, $size), "\0") !== '') {
                throw new InvalidArgumentException('out-of-range bits detected');
            }
            $bitset = \substr($bitset, 0, $size);
        }

        // truncate out-of-range bits of last byte
        $lastByteMaxOrd = $this->enumerationCount % 8;
        if ($lastByteMaxOrd !== 0) {
            $lastByte         = $bitset[-1];
            $lastByteExpected = \chr((1 << $lastByteMaxOrd) - 1) & $lastByte;
            if ($lastByte !== $lastByteExpected) {
                throw new InvalidArgumentException('out-of-range bits detected');
            }

            $this->bitset = \substr($bitset, 0, -1) . $lastByteExpected;
        }

        $this->bitset = $bitset;
    }
1124650
public void set(int bit, boolean value) {
    int bite = byteForBit(bit);
    ensureSpace(bite + 1);
    int bitOnByte = bitOnByte(bit, bite);
    if (value) {
      bits[bite] = byteBitSet(bitOnByte, bits[bite]);
    } else {
      bits[bite] = byteBitUnset(bitOnByte, bits[bite]);
    }
  }
619797
def bits_to_bytes(bits):
    
    if len(bits) % 8 != 0:
        raise Exception("num bits must be multiple of 8")

    res = ""

    for x in six.moves.range(0, len(bits), 8):
        byte_bits = bits[x:x+8]
        byte_val = int(''.join(map(str, byte_bits)), 2)
        res += chr(byte_val)

    return utils.binary(res)
676283
public void putString(int pos, CharSequence s) {
		for (int i = 0; i < s.length(); ++i) {
			char c = s.charAt(i);
			byte b0 = (byte)c;
			byte b1 = (byte)(c >> 8);
			if (_order == ByteOrder.BIG_ENDIAN) {
				putBytes(pos, b1, b0);
			} else {
				putBytes(pos, b0, b1);
			}
			pos += 2;
		}
	}
168800
public function bitString(): BitString
    {
        $last_octet_bits = $this->_width % 8;
        $unused_bits = $last_octet_bits ? 8 - $last_octet_bits : 0;
        return new BitString($this->_flags, $unused_bits);
    }