public static String bin2str ( final byte [ ] values , final JBBPBitOrder bitOrder , final boolean separateBytes ) { if ( values == null ) { return null ; } final StringBuilder result = new StringBuilder ( values . length * ( separateBytes ? 9 : 8 ) ) ; boolean nofirst = false ; for ( final byte b : values ) { if ( separateBytes ) { if ( nofirst ) { result . append ( ' ' ) ; } else { nofirst = true ; } } int a = b ; if ( bitOrder == JBBPBitOrder . MSB0 ) { for ( int i = 0 ; i < 8 ; i ++ ) { result . append ( ( a & 0x1 ) == 0 ? ' ' : ' ' ) ; a >>= 1 ; } } else { for ( int i = 0 ; i < 8 ; i ++ ) { result . append ( ( a & 0x80 ) == 0 ? ' ' : ' ' ) ; a <<= 1 ; } } } return result . toString ( ) ; }
Convert a byte array into string binary representation with defined bit order and possibility to separate bytes .