Script Library: 1247 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 
View scriptLicenseDownload documentation as: HTML or editable
Download scriptHistoryOther scripts by: vincentecuye

Documentation for: print-hex.r


REBOL

Print-Hex

Author: Vincent Ecuyer
Date: 4-Feb-2013
File: %print-hex.r

Contents:

1. Purpose
2. Usage
3. Example

1. Purpose

Displays binary data both in hexadecimal and filtered ASCII.

2. Usage

print-hex data /no-wait
  • data : source to examine (file! url! binary! string! port!)
  • /no-wait : doesn't stop until the source's end or a Ctrl-c

When launched from the command line, this script accepts a file argument:

$ r3 print-hex.r path/to/my/file

(the script name must not be altered or must be changed too in the "if %print-hex.r =" statement for this to work)

Like the AmigaDOS command "TYPE HEX NUMBER", this function shows binary data with numbered rows of 16 bytes, followed by their ASCII equivalent. Only the non-control pure ASCII values are printed (32 to 126), others are displayed as a single dot "."

It's mainly useful as a debugging tool or to examine unknown data, with cues like magic numbers or ids easily spottable.

For convenience, it pauses every 16 lines, waiting for either a quit command ('q', 'quit', 'x', 'exit'), or a newline to continue. The refinement /no-wait disables this behavior.

3. Example

>> print-hex %print-hex.r
00000000 : 5245424F 4C205B0D 0A202020 20546974  REBOL [..    Tit
00000010 : 6C653A20 22507269 6E742D48 65782220  le: "Print-Hex" 
00000020 : 0D0A2020 20204175 74686F72 3A202256  ..    Author: "V
00000030 : 696E6365 6E742045 63757965 7222200D  incent Ecuyer" .
00000040 : 0A202020 20446174 653A2031 2D466562  .    Date: 1-Feb
00000050 : 2D323031 33200D0A 20202020 56657273  -2013 ..    Vers
00000060 : 696F6E3A 20312E30 2E30200D 0A202020  ion: 1.0.0 ..   
00000070 : 2046696C 653A2025 7072696E 742D6865   File: %print-he
00000080 : 782E7220 0D0A2020 20205075 72706F73  x.r ..    Purpos
00000090 : 653A207B 44697370 6C617973 2062696E  e: {Displays bin
000000A0 : 61727920 64617461 20626F74 6820696E  ary data both in
000000B0 : 20686578 61646563 696D616C 20616E64   hexadecimal and
000000C0 : 2066696C 74657265 64204153 4349492E   filtered ASCII.
000000D0 : 7D200D0A 20202020 55736167 653A207B  } ..    Usage: {
000000E0 : 0D0A2020 20202020 20204C69 6B652074  ..        Like t
000000F0 : 68652041 6D696761 444F5320 636F6D6D  he AmigaDOS comm
MakeDoc2 by REBOL- 4-Feb-2013