private static byte[] toByteArrayReverse(BitSet bits) {
        byte[] bytes = new byte[bits.length() / 8 + 1];
        for (int i = 0; i < bits.length(); i++) {
            if (bits.get(i)) {
                final int value = bytes[i / 8] | (1 << (7 - (i % 8)));
                bytes[i / 8] = (byte) value;
            }
        }
        return bytes;
    }
private static byte [ ] toByteArrayReverse ( BitSet bits ) { byte [ ] bytes = new byte [ bits . length ( ) / 8 + 1 ] ; for ( int i = 0 ; i < bits . length ( ) ; i ++ ) { if ( bits . get ( i ) ) { final int value = bytes [ i / 8 ] | ( 1 << ( 7 - ( i % 8 ) ) ) ; bytes [ i / 8 ] = ( byte ) value ; } } return bytes ; }
Copied from: https://github.com/xetorthio/jedis/issues/301