Skip to content

Instantly share code, notes, and snippets.

@paullewallencom
Created July 26, 2018 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paullewallencom/f296444336509c93cad1a80b65f546bd to your computer and use it in GitHub Desktop.
Save paullewallencom/f296444336509c93cad1a80b65f546bd to your computer and use it in GitHub Desktop.
Reads Binary File and Writes Bits
public class BinaryDump
{
private BinaryDump() { }
public static void main( String[] args )
{
int bitsPerLine = 16;
if ( args.length == 1 )
{
bitsPerLine = Integer.parseInt( args[ 0 ] );
}
int count;
for ( count = 0; !BinaryStdIn.isEmpty(); count++ )
{
if ( bitsPerLine == 0 )
{
BinaryStdIn.readBoolean();
continue;
}
else if ( count != 0 && count % bitsPerLine == 0 ) StdOut.println();
if ( BinaryStdIn.readBoolean() ) StdOut.print( 1 );
else StdOut.print( 0 );
}
if ( bitsPerLine != 0 ) StdOut.println();
StdOut.println( count + " bits" );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment