public static String toBinaryString ( final byte [ ] data ) { if ( data == null ) { return null ; } final StringBuilder buf = new StringBuilder ( data . length * 8 ) ; for ( final byte element : data ) { byte bits = element ; for ( int j = 0 ; j < 8 ; j ++ ) { if ( ( bits & 0x80 ) == 0x80 ) { buf . append ( ' ' ) ; } else { buf . append ( ' ' ) ; } bits <<= 1 ; } } return buf . toString ( ) ; }
Returns a string formatted by bits .