home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l180 / 1.ddi / BIN2HEX.BAS < prev    next >
Encoding:
BASIC Source File  |  1989-02-07  |  2.4 KB  |  79 lines

  1.   ' ************************************************
  2.   ' **  Name:          BIN2HEX                    **
  3.   ' **  Type:          Program                    **
  4.   ' **  Module:        BIN2HEX.BAS                **
  5.   ' **  Language:      Microsoft QuickBASIC 4.00  **
  6.   ' ************************************************
  7.   '
  8.   ' Reads in any file and writes out a hexadecimal format file
  9.   ' suitable for rebuilding the original file using the HEX2BIN
  10.   ' program.
  11.   '
  12.   ' USAGE:          BIN2HEX inFileName.ext outFileName.ext
  13.   ' .MAK FILE:      BIN2HEX.BAS
  14.   '                 PARSE.BAS
  15.   ' PARAMETERS:     inFileName    Name of file to be duplicated in hexadecimal
  16.   '                               format
  17.   '                 outFileName   Name of hexadecimal format file to be created
  18.   ' VARIABLES:      cmd$          Working copy of the command line
  19.   '                 inFile$       Name of input file
  20.   '                 outFile$      Name of output file
  21.   '                 byte$         Buffer for binary file access
  22.   '                 i&            Index to each byte of input file
  23.   '                 h$            Pair of hexadecimal characters representing
  24.   '                               each byte
  25.   
  26.   
  27.     DECLARE SUB ParseWord (a$, sep$, word$)
  28.   
  29.   ' Initialization
  30.     CLS
  31.     PRINT "BIN2HEX "; COMMAND$
  32.     PRINT
  33.   
  34.   ' Get the input and output filenames from the command line
  35.     cmd$ = COMMAND$
  36.     ParseWord cmd$, " ,", inFile$
  37.     ParseWord cmd$, " ,", outFile$
  38.   
  39.   ' Verify that both filenames were given
  40.     IF outFile$ = "" THEN
  41.         PRINT
  42.         PRINT "Usage: BIN2HEX inFileName outFileName"
  43.         SYSTEM
  44.     END IF
  45.   
  46.   ' Open the input file
  47.     OPEN inFile$ FOR BINARY AS #1 LEN = 1
  48.     IF LOF(1) = 0 THEN
  49.         CLOSE #1
  50.         KILL inFile$
  51.         PRINT
  52.         PRINT "File not found - "; inFile$
  53.         SYSTEM
  54.     END IF
  55.   
  56.   ' Open the output file
  57.     OPEN outFile$ FOR OUTPUT AS #2
  58.   
  59.   ' Process each byte of the file
  60.     byte$ = SPACE$(1)
  61.     FOR i& = 1 TO LOF(1)
  62.         GET #1, , byte$
  63.         h$ = RIGHT$("0" + HEX$(ASC(byte$)), 2)
  64.         PRINT #2, h$; SPACE$(1);
  65.         IF i& = LOF(1) THEN
  66.             PRINT #2, ""
  67.         ELSEIF i& MOD 16 = 0 THEN
  68.             PRINT #2, ""
  69.         ELSEIF i& MOD 8 = 0 THEN
  70.             PRINT #2, "- ";
  71.         END IF
  72.     NEXT i&
  73.   
  74.   ' Clean up and quit
  75.     CLOSE
  76.     END
  77.   
  78.  
  79.