Search
Close this search box.

How to Read Hexadecimal Source Code on macOS

When dealing with unusual files, looking at the actual bits that compose the file can be hugely valuable. If nothing else, you can read the file’s headers and decipher its purpose. Editing hexadecimal code is a complex business, but it can be done with a variety of hex editors in macOS. What is hexadecimal code, and why is it worth examining?

What is Hexadecimal Code?

Let’s say you’ve got a corrupted file on your computer. You want to try and fix the file, which means you need to open up the file and look at the actual binary digits that make up the file. If you want to read the actual bits in a file instead of an applications interpretation of those bits, you have to interpret patterns of 1s and 0s to try and understand it.

Reading binary isn’t easy, which is where hexadecimal becomes useful. Why does hexadecimal exist? It provides a different, more “human readable” way to understand computer code. Reading binary isn’t so easy, but that’s how all computer code is compiled. Basically, humans can read hex easily, while computers can read binary easily.In computing, hexadecimal provides a more concise way to represent binary values.

How to Read Hexadecimal Code

Hexadecimal uses a base 16 number system instead of binary’s base 2. Thanks to the larger number space, multiple binary digits can be expressed in a single hex digit. If you are familiar with binary, you can read the example below to see the relationship.

Each hexadecimal digit expresses four binary digits. If you remember your binary, you’ll know that half a byte has exactly eight possible values – the same number of values a hex digit can have. Examine the table below to see the equivalencies.

Combine two hexadecimal numbers, and you can express eight bits of information. That’s equivalent to one byte with sixteen possible values. A single byte ranges from 0000 0000 to 1111 1111. In hexadecimal, that’s 00 through FF, respectively. By writing hexadecimal values as a series of pairs, you can easily “chunk” a file’s binary data into bytes.

Conventions for Reading and Writing Hexadecimal Values

When writing hexadecimal values, the characters 0x may begin the value. These characters label the following values as hexadecimal. Since hex, binary, and octal can all look the same at first glance, this reserved prefix avoids confusion and reduces error.

For example, 0x2FF0C4 describes a hexadecimal address in memory equivalent to a binary value of 0010 1111 1111 0000 1100 0100 and a decimal value of 3,141,828. Only 2FF0C4 counts as part of the value. The leading 0x characters only indicate the number system.

When an entire document is processed as hexadecimal, the values are shown as pairs, such as FF A0 2D CE. This helpfully separates the values into byte-length strings, making it easier for humans to parse.

Viewing and Editing Hexadecimal Code on macOS

You’ll need a hexadecimal viewer application to view hexadecimal code on macOS. There are a few options available, ranging from free and simple to professionally robust.

Once you have an application, you can open any file at all to view the underlying binary code presented in hexadecimal values. This is more useful for certain types of files than others, but in most cases you’ll see hexadecimal values on the left with the ASCII interpretation of those values on the right. This way you can “read” the file and begin to comprehend what’s happening.

Hex Editor Apps for macOS

0xED is a free and simple encoder that offers some customization options. The application is focused on the clear and speedy interpretation of hexadecimal values. It’s a rudimentary but useful introduction to hexadecimal editors.

Hex Fiend provides a more flexible but still affordable app for checking out hex code. It offers a better reading and selection experience than 0xed, and it’s what we use on a typical basis.

Synalyze It! is a professional-grade, paid hex interpreter with built-in color coding of values for visual file analysis. It also includes an enormous repository of “grammars.” These apply known file structures to hexadecimal code. These frames help you understand, interpret search, and edit the hex code.

Editing Hex Code

Hex editors can also edit hex code. It’s not quite as simple as editing text, however – nor is it as forgiving. Hex editors edit code in byte-length pairs, overwriting and replacing two values simultaneously. If you’re not extremely careful, you can corrupt a functional file instantaneously. To protect against this fragility, always duplicate a file before editing its hex code.

What Are Hex Editors Used For?

Just popping open random files in a hex editor might be fun. However, it’s not very useful. There are a narrow range of circumstances in which hex editors show their quality. If you need to view and edit binary code, then hex editors are the best tool for the job.

For example, while writing a program that outputs binary data, you should manually inspect the files for quality. They can also help recover or analyze corrupted third-party files. Hex editors can open any file, whether corrupted or invalid. This means you can sometimes “fix” a corrupted file with a hex editor or at least determine what’s causing the error. If you need to make a precise edit to a system file, such as changing a memory address in a kext, a hexadecimal editor is the only tool for the job. Thanks to their widespread utility, anyone interested in the nitty-gritty of computing and programming would do well to become familiar with a hex editor.

You might also like the following posts:

Play NES, SNES, and N64 Games on macOS With a Console Emulator

Reading and Writing to Windows Hard Drives in macOS

Pro Terminal Commands: Editing the SSH Configuration File

Share the Post:
Kokou Adzo

Kokou Adzo

Kokou Adzo is a stalwart in the tech journalism community, has been chronicling the ever-evolving world of Apple products and innovations for over a decade. As a Senior Author at Apple Gazette, Kokou combines a deep passion for technology with an innate ability to translate complex tech jargon into relatable insights for everyday users.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts