Viewing and Editing Hexadecimal Source in 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?

In computing, hexadecimal provides a more concise way to represent binary values. It 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. Each hexadecimal digit expresses four binary digits. If you remember your binary, you’ll know that half a byte has exactly 16 possible values – the same number of values a hex digit can have. Examine the table below to see the equivalencies.

hexadecimal-decimal-binary-equivalent-values

Combine two hexadecimal numbers, and you can express eight bits of information. That’s equivalent to one byte with thirty-two 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.

Essentially, hexadecimal and binary provide different “frames” for the same underlying data. Humans can read hex easily, while computers can read binary easily.

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 hexademical 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 free options available.

  • 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.

hexadecimal-editor-0xed-hero

  • 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.

hexadecimal-editor-synalyze-it-hero

Once you have either 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 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.

Conclusion: 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.

Leave a Comment

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.