Appends bits on to the end of the stack.
@param bits Storage for bits. Relevant bits start at the front.
@param numberOfBits Number of relevant bits in 'bits'
@param swapOrder If true then the first bit in 'bits' will be the last bit in this array.
338246
public void append( int bits , int numberOfBits , boolean swapOrder ) {
		if( numberOfBits > 32 )
			throw new IllegalArgumentException("Number of bits exceeds the size of bits");
		int indexTail = size;
		growArray(numberOfBits,true);

		if( swapOrder ) {
			for (int i = 0; i < numberOfBits; i++) {
				set( indexTail + i , ( bits >> i ) & 1 );
			}
		} else {
			for (int i = 0; i < numberOfBits; i++) {
				set( indexTail + numberOfBits-i-1 , ( bits >> i ) & 1 );
			}
		}
	}
82871
public void addOrder(Order... orders) {
		if(null != this.orders){
			ArrayUtil.append(this.orders, orders);
		}
		this.orders = orders;
	}
1157037
public void writeBit(int value, int number) throws IOException {
    int localNumber = number;
    while (localNumber > 0) {
      localNumber--;
      bitBuffer |= ((value & 1) << bitCount++);
      if (bitCount == 8) {
        createByte();
      }
    }
  }
268489
public void append(short bits) {
        long l;
        long[] a1;
        l = ((l = crc) >> 8L) ^ (a1 = CRC32_TABLE)[(int) ((l & 0xFF) ^ (long) (bits & 0xFF))];
        crc = (l >> 8L) ^ a1[(int) ((l & 0xFF) ^ (long) ((bits & 0xffff) >> 8))];
    }
54088
public void fill_1(byte[] v, int byteoff, int nbits, int bitoff) {
      if (nbits < 0) throw new NegativeArraySizeException("nbits < 0: " + nbits);
      if (byteoff < 0) throw new IndexOutOfBoundsException("byteoff < 0: "+ byteoff);
      if (bitoff < 0) throw new IndexOutOfBoundsException("bitoff < 0: " + bitoff);
      assert v == null || byteoff + ((nbits-1) >> 3) + 1 <= v.length;
      _val = v;
      _nbits = nbits;
      _bitoff = bitoff;
      _byteoff = byteoff;
    }
1038427
public static void swap(byte[] byteArray, int index1, int index2) {
        TrivialSwap.swap(byteArray, index1, byteArray, index2);
    }
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)
877065
public int get_bits(int number_of_bits)
  {
  	int				returnvalue = 0;
  	int 			sum = bitindex + number_of_bits;

	// E.B
	// There is a problem here, wordpointer could be -1 ?!
    if (wordpointer < 0) wordpointer = 0;
    // E.B : End.

  	if (sum <= 32)
  	{
	   // all bits contained in *wordpointer
	   returnvalue = (framebuffer[wordpointer] >>> (32 - sum)) & bitmask[number_of_bits];
	   // returnvalue = (wordpointer[0] >> (32 - sum)) & bitmask[number_of_bits];
	   if ((bitindex += number_of_bits) == 32)
	   {
		 bitindex = 0;
		 wordpointer++; // added by me!
	   }
	   return returnvalue;
    }

    // E.B : Check that ?
    //((short[])&returnvalue)[0] = ((short[])wordpointer + 1)[0];
    //wordpointer++; // Added by me!
    //((short[])&returnvalue + 1)[0] = ((short[])wordpointer)[0];
	int Right = (framebuffer[wordpointer] & 0x0000FFFF);
	wordpointer++;
	int Left = (framebuffer[wordpointer] & 0xFFFF0000);
	returnvalue = ((Right << 16) & 0xFFFF0000) | ((Left >>> 16)& 0x0000FFFF);

    returnvalue >>>= 48 - sum;	// returnvalue >>= 16 - (number_of_bits - (32 - bitindex))
    returnvalue &= bitmask[number_of_bits];
    bitindex = sum - 32;
    return returnvalue;
}
508942
def put_bits( self, value, count ):
        
        for _ in range( count ):

            # bits are retrieved from the source LSB first
            bit = (value & 1)
            value >>= 1

            # however, bits are put into the result based on the rule
            if self.bits_reverse:
                if self.insert_at_msb:
                    self.current_bits |= (bit << (self.bits_remaining-1))
                else:
                    self.current_bits <<= 1
                    self.current_bits |= bit
            else:
                if self.insert_at_msb:
                    self.current_bits >>= 1
                    self.current_bits |= (bit << 7)
                else:
                    self.current_bits |= (bit << (8-self.bits_remaining))

            self.bits_remaining -= 1
            if self.bits_remaining <= 0:
                self.output.append( self.current_bits )

                self.current_bits = 0
                self.bits_remaining = 8
1208010
public static void shuffle(byte[] byteArray) {
		int swapPlace = -1;

		for(int i = 0; i < byteArray.length; i++) {
			swapPlace = (int) (Math.random() * (byteArray.length - 1 ));
			XORSwap.swap(byteArray, i, swapPlace);
		}
	}
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]);
    }
  }
733122
private int countNonNegativeBits(final Tristate[] bits) {
    int result = 0;
    for (final Tristate bit : bits)
      if (bit != Tristate.FALSE)
        result++;
    return result;
  }
1037379
public void writeZeroes(int bits) throws IOException {
        if (bits == 0) return;
        if (!ensureSize(bits)) throw new IOException("Memory Allocation Error");
        totalBits += bits;
        while (bits > 0) {
            int n = Math.min(BITS_PER_BLURB - outBits, bits);
            buffer[outBlurbs] <<= n;
            bits -= n;
            outBits += n;
            if (outBits == BITS_PER_BLURB) {
                outBlurbs++;
                outBits = 0;
            }
        }
    }
42775
public JBBPOut Short(final String str, final JBBPBitOrder bitOrder) throws IOException {
    assertNotEnded();
    if (this.processCommands) {
      final boolean msb0 = bitOrder == JBBPBitOrder.MSB0;
      for (int i = 0; i < str.length(); i++) {
        short value = (short) str.charAt(i);
        if (msb0) {
          value = (short) JBBPFieldShort.reverseBits(value);
        }
        _writeShort(value);
      }
    }
    return this;
  }
1071791
public void writeBits(int b, int n) throws IOException {
		if (n <= capacity) {
			// all bits fit into the current buffer
			buffer = (buffer << n) | (b & (0xff >> (BITS_IN_BYTE - n)));
			capacity -= n;
			if (capacity == 0) {
				ostream.write(buffer);
				capacity = BITS_IN_BYTE;
				len++;
			}
		} else {
			// fill as many bits into buffer as possible
			buffer = (buffer << capacity)
					| ((b >>> (n - capacity)) & (0xff >> (BITS_IN_BYTE - capacity)));
			n -= capacity;
			ostream.write(buffer);
			len++;

			// possibly write whole bytes
			while (n >= 8) {
				n -= 8;
				ostream.write(b >>> n);
				len++;
			}

			// put the rest of bits into the buffer
			buffer = b; // Note: the high bits will be shifted out during
			// further filling
			capacity = BITS_IN_BYTE - n;
		}
	}
1212992
public void setStopbits(String stopbits) {
        if (ModbusUtil.isBlank(stopbits) || stopbits.equals("1")) {
            this.stopbits = AbstractSerialConnection.ONE_STOP_BIT;
        }
        else if (stopbits.equals("1.5")) {
            this.stopbits = AbstractSerialConnection.ONE_POINT_FIVE_STOP_BITS;
        }
        else if (stopbits.equals("2")) {
            this.stopbits = AbstractSerialConnection.TWO_STOP_BITS;
        }
    }
1205011
void writeBits(ByteBuf out, final int count, final long value) {
        if (count < 0 || count > 32) {
            throw new IllegalArgumentException("count: " + count + " (expected: 0-32)");
        }
        int bitCount = this.bitCount;
        long bitBuffer = this.bitBuffer | value << 64 - count >>> bitCount;
        bitCount += count;

        if (bitCount >= 32) {
            out.writeInt((int) (bitBuffer >>> 32));
            bitBuffer <<= 32;
            bitCount -= 32;
        }
        this.bitBuffer = bitBuffer;
        this.bitCount = bitCount;
    }