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

  1.   ' ************************************************
  2.   ' **  Name:          HEX2BIN                    **
  3.   ' **  Type:          Program                    **
  4.   ' **  Module:        HEX2BIN.BAS                **
  5.   ' **  Language:      Microsoft QuickBASIC 4.00  **
  6.   ' ************************************************
  7.   '
  8.   ' Reads in a hexadecimal format file and writes out a binary
  9.   ' file created from the hexadecimal byte numbers.
  10.   '
  11.   ' USAGE:           HEX2BIN inFileName.ext outFileName.ext
  12.   ' .MAK FILE:       HEX2BIN.BAS
  13.   '                  PARSE.BAS
  14.   '                  STRINGS.BAS
  15.   ' PARAMETERS:      inFileName.ext   Name of hexadecimal format file to be read
  16.   '                  outFileName.ext  Name of file to be created
  17.   ' VARIABLES:       cmd$       Working copy of the command line
  18.   '                  inFile$    Name of input file
  19.   '                  outFile$   Name of output file
  20.   '                  h$         Pair of hexadecimal characters representing
  21.   '                             each byte
  22.   '                  i%         Index into list of hexadecimal character pairs
  23.   '                  byte$      Buffer for binary file access
  24.   
  25.     DECLARE SUB ParseWord (a$, sep$, word$)
  26.     DECLARE FUNCTION FilterIn$ (a$, set$)
  27.   
  28.   ' Get the input and output filenames from the command line
  29.     cmd$ = COMMAND$
  30.     ParseWord cmd$, " ,", inFile$
  31.     ParseWord cmd$, " ,", outFile$
  32.   
  33.   ' Verify both filenames were given
  34.     IF outFile$ = "" THEN
  35.         PRINT
  36.         PRINT "Usage: HEX2BIN inFileName.ext outFileName.ext"
  37.         SYSTEM
  38.     END IF
  39.   
  40.   ' Open the input file
  41.     OPEN inFile$ FOR INPUT AS #1
  42.   
  43.   ' Truncate the output file if it already exists
  44.     OPEN outFile$ FOR OUTPUT AS #2
  45.     CLOSE #2
  46.   
  47.   ' Now open it for binary output
  48.     OPEN outFile$ FOR BINARY AS #2 LEN = 1
  49.   
  50.   ' Process each line of the hexadecimal file
  51.     DO
  52.         LINE INPUT #1, h$
  53.         h$ = FilterIn$(UCASE$(h$), "0123456789ABCDEF")
  54.         FOR i% = 1 TO LEN(h$) STEP 2
  55.             byte$ = CHR$(VAL("&H" + MID$(h$, i%, 2)))
  56.             PUT #2, , byte$
  57.         NEXT i%
  58.     LOOP WHILE NOT EOF(1)
  59.   
  60.   ' Clean up and quit
  61.     CLOSE
  62.     END
  63.   
  64.  
  65.