DEFINT A-Z DECLARE SUB CreateHexFile (FILENAME$, CONTENT$) ' These are hexadecimal digits that we will use to generate a list: X$ = "0123456789abcdef" ' This is what we will write to the file... MYLIST$ = "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f " ' We use two FOR loops to generate the rest of the list: FOR I = 2 TO 16 FOR J = 1 TO 16 MYLIST$ = MYLIST$ + MID$(X$, I, 1) + MID$(X$, J, 1) + " " NEXT J NEXT I CLS PRINT "This is the list of hexadecimal values that we will write to a file:" PRINT PRINT MYLIST$ PRINT CreateHexFile "ASCIIBAS.BIN", MYLIST$ PRINT "File saved successfully." PRINT END ' ' This function creates a file in binary mode and writes some bytes into it. ' The CONTENT$ string should hold a string of hexadecimal numbers. ' The numbers will be grouped into pairs, and each pair will ' be converted to a byte and written to the file. ' Non-hexadecimal characters will be ignored. ' ' This function can be used to create small binary files (less than 2K). ' SUB CreateHexFile (FILENAME$, CONTENT$) ' Create a file... OPEN FILENAME$ FOR OUTPUT AS #1 D = 0 ' We use this to count the hexadecimal digits FOR I = 1 TO LEN(CONTENT$) ' P = INSTR("0123456789ABCDEF", UCASE$(MID$(CONTENT$, I, 1))) ' IF P > 0 THEN ' D = D + 1 ' P = P - 1 ' The above code block calls UCASE$() function every time, ' but we can eliminate that by doing the following instead: ' P = INSTR("123456789abcdef0123456789ABCDEF", MID$(CONTENT$, I, 1)) IF P > 0 THEN D = D + 1 P = P AND 15 IF D AND 1 THEN HI = P * 16 ELSE C$ = CHR$(HI + P) PRINT #1, C$; END IF END IF NEXT I ' Write last digit if there were an odd number of digits: IF D AND 1 THEN PRINT #1, CHR$(HI); CLOSE #1 END SUB