Hexview - Hexadecimal File Display

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa® 365 Puzzlers  Calendar 2017

Mensa® 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

 

HexView will display the contents of any file using hexadecimal (base 16) digits.   There are 16 hexadecimal digits with values 0 through 15 but labeled "0" through "9" and "A" though "F" for convenience.  Each hex digit could also be written with 4 binary bits (0000 to 1111).   

 

 Hexadecimal numbers are convenient for use in displaying computer memory or files  because two of those 4 bit hex digits can represent the basic unit of memory storage, the 8-bit "byte"

 

I've had a version of this one floating around for my own use for years, but just recently realized that i had never posted it. 

 

Use of the program is self explanatory; , select a file to browse and use PgUp, PgDn keys to page through it.  Ctrl+PgUp will jump to page 1, Ctrl+PgDn will jump to the last page.  The "Esc"  escape key will close the file.  Characters which represent valid characters will be displayed on each line beside the hexadecimal data. 

 

Programmer's Notes

 

A TFileStream control is used to access the file to be displayed.   In order to avoid memory problems with large files, the amount of data (BufLen) to fill a page is calculated for each display operation based on the current size of the TMemo control.  For each page, procedure ShowPage seeks to the start of the next page to be displayed (CurPage*BufLen) and reads BufLen bytes of data.   Hexchars is the array containing the 16 hexadecimal character labels.  The Delphi code  uses a loop on N and J to convert each byte for each line into two display characters and add it to the string, Hex.  N reflects the position of the current line start within the buffer and J points tpo the current character being converted.  The conversion line of code looks like this:


hex:=hex+hexchars[(buffer[n+j] and $F0) shr 4] + hexchars[(buffer[n+j] and $0F)];

 

The left hand "nibble" (4 bits of a byte) is converted by "and"ing it with hex F0 (11110000 binary) to clear out the right side nibble and then shifted right (= divided by 16) to get it back in the range 0-15 which is then used as an index into the Hexchars array.  The right half of the bite is then converted similarly except that there's no need to divide by 16.

 

The displayed lines are added to a TStringlist (List) whose strings are assigned  to the Memo1.Lines property after the page has been built.  This eliminated a flicker problem that occurred when lines were built directly into Memo1.

 

One more interesting problem that I ran into and which might save some time for you in the future.  When a control is aligned to the bottom of the form (like the TStatictext control in this case), and the form is resized to a smaller height, the control is placed below any existing controls.  Adjusting the sizes in the OnResize exit is too late to prevent this problem.   The solution is to use the OnCanResize exit to predict where the bottom aligned control will be and readjust the size and tops of the other controls in advance of the actual resize operation..    

 

Running/Exploring the Program 

 

Download Source

Download Executable

 

Created: October 17, 2007

Modified: May 11, 2018

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2018, Gary Darby    All rights reserved.