The APL Programming Language

Hex Dump Example Program


Click below to go directly to a specific section:
Description | Source Code | Sample Run | Program Notes

Description

This is a small dump program, which opens up a file and displays its data in hexadecimal and ASCII format. The non-ASCII symbols of APL are represented in braces {keyword}

Source Code

[0]    Z{<-}HEXDUMP F;B;E;H;N;P;Q;V;#IO
[1]    @ Hex dump of file F
[2]    #IO{<-}0                     @ use index origin 0
[3]
[4]    @ Read the file (using APL*PLUS operations)
[5]    N{<-}-1+0{max}{max}/-#NNUMS  @ available tie number
[6]    F #NTIE N                    @ open the file
[7]    E{<-}#NSIZE N                @ file size
[8]    V{<-}#NREAD N,82,E,0         @ read file as character data
[9]    #NUNTIE N                    @ close the file
[10]
[11]   @ Form the hex dump
[12]   Q{<-}16                         @ display 16 bytes/line
[13]   N{<-}{ceiling}E{divide}Q        @ number of lines
[14]   Z{<-}8 HEX Q{times}{iota}N      @ addresses
[15]   Z{<-}(0 2+{shape}Z){take}Z      @ add two blank columns
[16]   H{<-},' ',2 HEX #AV{iota}V      @ data in hex
[17]   P{<-}(Q{times}3){reshape}' '    @ padding for short last row
[18]   H{<-}(N,Q{times}3){reshape}H,P  @ turn hex display into a matrix
[19]   Z{<-}Z,(0 3+{shape}H){take}H    @ append it to the result
[20]   B{<-}#AV[127],32{take}#AV       @ nonprinting chars
[21]   V[(V{epsilon}B)/{iota}{shape}V]{<-}'.' @ change 'em to "."
[22]   Z{<-}Z,(N,Q){reshape}V,P        @ append ASCII display to result

[0]    Z{<-}N HEX V
[1]    @ N-digit hex representation of values V
[2]    Z{<-}'0123456789ABCDEF'[{transpose}(N{reshape}16){represent}V]

Sample Run

        HEXDUMP'\APL.BAT'
00000000   40 65 63 68 6F 20 53 74 61 72 74 69 6E 67 20 41        @echo Starting A
00000010   50 4C 2A 50 4C 55 53 20 49 49 2F 33 38 36 2E 2E      PL*PLUS II/386..
00000020   2E 0D 0A 40 65 63 68 6F 20 6F 66 66 0D 0A 63 3A   ...@echo off..c:
00000030   0D 0A 63 64 20 5C 61 70 6C 33 38 36 0D 0A 7A 69   ..cd \apl386..zi
00000040   70 70 79 35 20 65 76 6C 65 76 65 6C 3D 31 0D 0A     ppy5 evlevel=1..
00000050   63 64 20 5C 0D 0A 63 61 6C 6C 20 62 79 65 0D 0A   cd \..call bye..
00000060   65 63 68 6F 20 6F 6E 1A 0D 0A 1A                             echo on....

Program Notes

This program was not tested and run personally by myself, due to not owning a keyboard containing the APL special non-ASCII symbols, or an APL card. This program was supplied thanks to
Jim Weigang's APL Information . This program is exactly the same as the hex dump program located on Jim's page. Jim also has a few more programs on his site that are worth taking a look at.
[Back] [Home]

Last modified: 10:00 PM on 11/24/1996