Created
July 26, 2018 18:36
-
-
Save paullewallencom/f296444336509c93cad1a80b65f546bd to your computer and use it in GitHub Desktop.
Reads Binary File and Writes Bits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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