Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Shortest code for a hexdump program, Anyone?

views
     
TSMatQuasar
post Nov 2 2025, 04:28 PM, updated 2 months ago

Casual
***
Validating
329 posts

Joined: Jun 2023
The code must be able to open a file, and print the address, hex value, and ASCII char side-by-side like below:

CODE
00000000    7F  45  4C  46  02  01  01  03  00  00  00  00  00  00  00  00      .ELF............
00000010    02  00  3E  00  01  00  00  00  B0  00  40  00  00  00  00  00      ..>.......@.....
00000020    40  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00      @...............
00000030    00  00  00  00  40  00  38  00  02  00  40  00  00  00  00  00      ....@.8...@.....


Anyone want to try?

My shortest code is in FASM, but you can try in other programming language.

You can use third-party library or system library.

My solution: (you can import the function in C/ C++ / C#)
» Click to show Spoiler - click again to hide... «


This post has been edited by MatQuasar: Nov 2 2025, 05:23 PM
techm
post Nov 2 2025, 10:18 PM

Getting Started
**
Junior Member
123 posts

Joined: Nov 2007
Where's the fun in in using a library function that does all the heavy lifting for you? 🤣
TSMatQuasar
post Nov 3 2025, 12:27 AM

Casual
***
Validating
329 posts

Joined: Jun 2023
QUOTE(techm @ Nov 2 2025, 10:18 PM)
Where's the fun in in using a library function that does all the heavy lifting for you? 🤣
*
Because in this age where coding means "plumbing 500 library calls together" instead of making your own algorithms... haha

Seriously, I have a hexdump program done in proper coding without using library function, just borrow Int2Hex from others.
It is all here, but the code is much longer: https://forum.lowyat.net/topic/5093005

My solution in post #1 of this thread is only 6 lines:
CODE

invoke CreateFileA,......
invoke ReadFile,....
invoke CryptBinaryToStringA,......
invoke GetStdHandle,.......
invoke WriteConsoleA,........
invoke ExitProcess,......


But it is longer if to support command-line argument parsing.

This post has been edited by MatQuasar: Nov 4 2025, 11:14 PM

 

Change to:
| Lo-Fi Version
0.0424sec    0.99    5 queries    GZIP Disabled
Time is now: 21st December 2025 - 12:44 PM