/** * Converts the given value into a desired bit order. * * @param aValue * the value to convert; * @param aBitCount * the number of bits that are supposed to be in the given value; * @param aBitOrder * the desired bit order. * @return the converted value. */ public static int convertBitOrder( final int aValue, final int aBitCount, final BitOrder aBitOrder ) { if ( ( aBitCount <= 0 ) || ( aBitCount > 32 ) ) { throw new IllegalArgumentException( "Bit count cannot be zero, negative or beyond 32-bits!" ); } // We already have the most significant bit first, convert only if the bit // order is LSB first... if ( aBitOrder == BitOrder.MSB_FIRST ) { return ( aValue & getBitMask( aBitCount ) ); } return reverseBits( aValue, aBitCount ); }
symbol = reverseBits( symbol, bitCount );