I was recently tasked with creating a simple command line program that would take an input of a file of unknown contents and print a hex dump as the output. However, I didn’t really know how I could access the data of the file to begin with, and I didn’t know what a hex dump was. So I’m going to share with you what I learned and what I wrote to accomplish this task.
Since I’m most familiar with JavaScript, I decided to do this in Node. The aim is to write a command like this:

node hexdump.js data

Which will run a hexdump.js program on a file (data) and output the hex dump.
The file can be anything - an image, a binary, a regular text file, or a file with other encoded data. In my particular case, it was a ROM.
If you’ve ever tried opening a non text-based file with a text editor, you’ll remember seeing a jumbled mess of random characters. If you’ve ever wondered how a program could access that raw data and work with it, this article might be enlightening.

#javascript #node #programming

Understanding Bits, Bytes, Bases, and Writing a Hex Dump in JavaScript
1.65 GEEK