AnonymousNamefag

bindump.c

Mar 23rd, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. /*******************************
  2.  * Bindump 1.0 (Binary Dump)   *
  3.  * Author: Michael Warren      *
  4.  * Date: Sat Mar 23 2019       *
  5.  * License: Michael Warren FSL *
  6.  *******************************/
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <stdint.h>
  11. #include <errno.h>
  12.  
  13. int main( int argc, char **argv ){
  14.     FILE *fp;
  15.     int c;
  16.     if( !(fp = fopen( argv[1], "r" )) ){
  17.         perror( argv[0] );
  18.         exit( errno );
  19.     }
  20.     while( (c = fgetc( fp )) != EOF ){
  21.         uint8_t b = 0x80;
  22.         while( b ){
  23.             if( b & c ) putchar( '1' );
  24.             else putchar( '0' );
  25.             b >>= 1;
  26.         }
  27.         putchar( ' ' );
  28.         if( ftell( fp ) % 8 == 0 ) putchar ( '\n' );
  29.     }
  30.     fclose( fp );
  31.     putchar( '\n' );
  32.     return 0;
  33. }
Add Comment
Please, Sign In to add comment