85

Hex and binary are two different bases. Hex, in my understanding, is simply an easier to use and more convenient version of binary.

However, I often hear that hex editors are binary editors. If you search for "binary editor" on Google, you get hex editors.

1
  • 4
    Hex is somewhat readable representation of binary data.
    – Salman A
    Mar 28, 2016 at 12:06

12 Answers 12

186

A binary editor edits a file as a binary file.

Binary file - Wikipedia

A binary file is a computer file that is not a text file. The term "binary file" is often used as a term meaning "non-text file" [and is] usually thought of as being a sequence of bytes. ... Binary files typically contain bytes that are intended to be interpreted as something other than text characters.

A hex editor is a type of binary editor in which the data is represented in hexadecimal.

Hex editor - Wikipedia

A hex editor (or binary file editor or byte editor) is a type of computer program that allows for manipulation of the fundamental binary data that constitutes a computer file. The name 'hex' comes from 'hexadecimal': a standard representation for numbers that has 16 as its base.

0
86

Terminology is hard. Different people have all sorts of different names for things.

In this instance, it appears that the hex in "hex editor" refers to the conventional human-readable representation of each byte's value, whereas the binary in "binary editor" refers to the notion that you're indeed editing the file at the byte layer (and computers store bytes in binary), without consideration for higher-level text encoding and the like. Recall that files not readily representable in higher-level text form are called "binary files" or "binaries", for the same reason.

Neither is technically incorrect; they just come at the naming problem from different angles. On a personal note, though, I would tend to agree that "binary editor" is confusing on balance.

0
58

Binary editor display (in binary)

00000000 | 11111011 11111011 11111011 11111011 11110101 11111011 11111011 11111011
00001000 | 11111011 11111011 11111011 11111011 11111011 11111011 11111011 11111011
00010000 | 11111011 11111011 11111011 11111011 11111011 11111011 11111011 11111011
00011000 | 11110101 11111011 11111011 11111011 11111011 11111011 11111011 11111011
00100000 | 11111011 11111011 11111011 11111011 11111011 11111011 11111011 11111011
00101000 | 11111011 11111011 11101111 11111011 11111011 11111011 11111011 11111011
00110000 | 11111011 11111011 11111011 11111011 11111011 11111011 11111011 11111011
00111000 | 11111011 11111011 11111011 11101111 11111011 11111011 11111011 11111011
01000000 | 11111011 11111011 11111011 11111011 11111011 11111011 11111011 11111011
01001000 | 11111011 11111011 11111011 11111011 11111011 11111011 11111011 11111011
01010000 | 11101111 11111011 11111011 11111011 11111011 11111011 11111011 11111011
01011000 | 11101111 11111011 11111011 11111011 11111011 11111011 11111011 11111011
01100000 | 11111011 11111011 11111011 11111011 11111011 11101111 11111011 11111011
01101000 | 11111011 11111011 11111011 11111011 11111011 11111011 11111011 11111011

Binary editor display (in hexadecimal)

00 | fb fb fb fb f5 fb fb fb fb fb fb fb fb fb fb fb
10 | fb fb fb fb fb fb fb fb f5 fb fb fb fb fb fb fb 
20 | fb fb fb fb fb fb fb fb fb fb ef fb fb fb fb fb 
30 | fb fb fb fb fb fb fb fb fb fb fb ef fb fb fb fb 
40 | fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb 
50 | ef fb fb fb fb fb fb fb ef fb fb fb fb fb fb fb 
60 | fb fb fb fb fb ef fb fb fb fb fb fb fb fb fb fb

It is true that a binary editor should let you handle bytes in binary, but as you can see the base 2 is too small to give compact numerals.

Binary as raw, not base two

Generally speaking, then "binary" in binary editor doesn't refer to the base two, it actually is the antonym of "text editor".
The difference being that text editors are designed to show text, so non printing characters, new lines, control chars, invalid utf-8 code units and so on are not required to be handled safely.
The mere act of opening a file and immediately saving it can change it (due to the editor internal conversions, failures).

Binary editors on the other way, don't try to give the data any semantic and let the user safely handle it as a stream of bytes/bits/words.

Hexadecimal editors

The perfect binary editor would known every possible binary format and let you edit it, but since everyone can make its own binary format and since they change very often, it is futile to try to support all formats.
The best thing an editor could do is showing the bytes themselves, and due to the, already discussed, properties of base 16, hexadecimal numerals are very handy!

Also an experienced user can mentally translate bin to hex as they read it.
Setting/getting a bit out of a byte written in hex takes really absolutely no more effort than a byte written in bin.
To be honest I found hex easier than binary to read.

8
  • 1
    Nice examples showing the difference. Actually seeing them side by side makes the hex look so much nicer
    – DrZoo
    Mar 23, 2016 at 18:36
  • 1
    @DrZoo Unless you're dealing with bit-fields, in which case the binary representation is much nicer! en.wikipedia.org/wiki/Bit_field.
    – misha256
    Mar 24, 2016 at 4:33
  • 6
    misha256: honestly, when I look at hex - I see binary. I read "f" but my brain immediately says "1111". It's like a viewing the matrix in compact form. :)
    – tdrury
    Mar 24, 2016 at 13:10
  • 4
    +1 for emphasizing "Binary as raw, not base two"
    – Kelvin
    Mar 24, 2016 at 15:36
  • 5
    @tdrury good point, I suppose after a while you just start to "see" what you need to see regardless of how it's expressed. Haha, yeah, Matrix! Reminds me of a guy I went to school with who happily coded machine language in hex or decimal and could convert freely between the two. He knew all the op-codes by heart and saw bit-fields and other packed data structures like it was his first language. Those were the Commodore 64 days mind you (far simpler days), but still an impressive talent.
    – misha256
    Mar 24, 2016 at 23:22
16

Why are hex editors called binary editors?

Summary:

A Hex Editor is used to directly edit a binary file by displaying the binary content in hexadecimal format and allowing these hexadecimal numbers to be changed.

Notes:

  • Hex Editors allows editing of the raw data contents of a file, instead of other programs which attempt to interpret the data.

  • Hex Editors as also called Binary Editors or Byte Editors.

  • Calling them Binary Editors or Byte Editors is not really correct as the editors are changing hexadecimal numbers and not binary numbers or bytes (of course the underlying binary numbers and bytes will change if the file is saved)

Why do we edit binary use hexadecimal?

It is easier to directly view or edit/modify binary files by displaying the data in hexadecimal form and changing the hexadecimal values.

  • One convenient way of representing binary numbers is using hexadecimal.

  • Historically computers were programmed in assembly language, where code was written using processor instructions and meta-statements (known variously as directives, pseudo-instructions and pseudo-ops), comments and data.

    • The code is translated into binary using an assembler. The binary code can then be loaded into a process and executed.

    • Without the source code it is easier to modify the program directly using an editor that displays the program in hexadecimal rather than binary.

  • Binary code is more easily readable by humans when converted into hexadecimal.

    For example, which pair of number is easier to memorise or read out to someone else?

    10110000 01100001
    

    Or

    B0 61
    
  • Each hexadecimal digit represents four binary digits (bits). One hexadecimal digit represents a nibble, which is half of an octet or byte (8 bits).

    For example, byte values can range from 0 to 255 (decimal), but may be more conveniently represented as two hexadecimal digits in the range 00 to FF.

  • Hexadecimal is also commonly used to represent computer memory addresses.

1
  • 3
    Also note that, while Base 64 might seem even easier to memorize, we stick to Hex because it has the nice property of mapping 2 chars ⇒ 1 byte.
    – PythonNut
    Mar 22, 2016 at 21:36
9

According to several programming language and operating system conventions, there are two kinds of files:

  • text files which are made of a suite of text lines, each line being composed of a suite of printable characters (including some control characters) and terminated by end of lines
  • binary files that contain an arbitrary suite of bytes including the null byte which is forbidden in a text file.

Text editors are able to open text files while binary editors have no restrictions on the kind of files they process.

The fact binary editors often represent and allows entering data in hexadecimal is just a convenience (they often display and allow replacing ascii characters too), only displaying data in pure binary would make the data less legible.

A popular binary editor is named HexEdit.

enter image description here

It rightly considers itself both a binary editor and an hex editor:

enter image description here

There is even an option not to display the data in hex but only the text

enter image description here

5

Files on the great majority, if all, of computers today are 8-bit bytes. That's typically the abstraction one is working with when directly editing a file.

Of course, there is occasion to actually edit individual bits of data, but not often. Common bit-level operations like setting bit 7 are easy to do with hex anyway - 1000 0000base2 = 80base16, so if a hex value is under 80base2 bit 7 is clear and adding 8base16 will set it.

Other reasons why hex is more strongly associated to this type of activity:

  • Hex values are easier to recognize when visually scanning for known values. For example, 20base16 = 32 which is an ASCII space, but the same value 0010 0000base2 isn't so easy to recognize as such among a flood of other dumped values.

  • Old systems where you actually needed to use this on a regular basis may have had limited screen space (e.g. 40 columns). The Apple IIe ROM monitor is a great example, it can dump memory in hex to the 40-column integrated video, and expanding values to binary on an 80x24 screen will run you out of room quickly. For these old systems, it's also easier to write routines to convert inputted ASCII back to the right values. Important where 4K of RAM was considered a lot of memory and systems may have only had as much ROM.

  • The word "hex" sounds better, is shorter, and is easier to type.

5

When people are using hex, they are usually thinking in binary and using the hex as a shorthand notation.

Sixteen is a power of 2. Eight is also a power of two. So 16 and 8 have been used for shorthand notation of binary. Manual conversion between binary, and a base of some power of two is easy. Just group the bits together in the size indicated by the target base, and then use the corresponding digit.

Base 8, octal, was popular for many early computers, which is why Unix has an od octal dump command. Each octal digit represents 3 bits at a time. But it was inconvenient for machines based on 8 bit bytes.

Hexadecimal, hex for short, base 16, represents 4 bits per digit. This is much a more commonly used representation these days.

3

This refers to how computers store information.

On the basic level computers use 0 and 1 to represent data, these are called bits. Eight bits grouped together is a byte. Hexadecimal is base 16 which means it has 16 characters (0-9, A-F). To store a character it takes 8 bits or 1 byte.

So a hexadecimal number 13 (19 in decimal) is the same as 0001 0011 in binary. It is easier to read hex than it is binary.

0
2

Earliest binary editors I know were also disassemblers. Meaning, the editing capability was a byproduct to the disassembling and patching of an executable binary file.

A good example of such application is Hiew.

Assembled code (assembler instructions) is often represented as hexadecimal strings. I think, this is where modern confusion arises. People just don't know, what they are dealing with.

2

Any compiled, runnable file (like somefile.exe, for example, on Windows) is sometimes called a "binary", since it's been compiled into machine-level code which is correct on the binary level to be executed by the processor directly.

So you're editing a binary. It just happens to be displayed in hex because hex is useful for humans.

1
  • Yes, but many data files are binary as well. They save on space and translation when they are read by the appropriate application. Also, even text files are often encrypted or compressed making them binary files.
    – Joe
    Mar 28, 2016 at 23:55
2

I'm going to answer your questions literally.

First, a bit of clarification. You mean, of course, a hexadecimal editor. Hex means 6 and decimal means 10, so hexadecimal means 16. Bi means 2. As you said these are two different bases, base 16 and base 2, which means it takes 16 placeholder elements to define a hexadecimal number and just 2 elements to define a binary number.

You said that,

If you actually search for "binary editor" on Google, you get hex editors.

And now for your questions,

Why is that? 

This is the literal part. Google returns what most people thought were satisfactory results of their searches. Their machine learning algorithms associate the strings "hexadecimal" and "hex" with "binary" within the context of the string "editor". Since most users were satisfied with "hex" "editor" after they searched for "binary" "editor", that's what we get. It has no meaning otherwise.

What is the connection?

Literally again, there is none since Google returns no meaning. Google does not know the difference between binary and hexadecimal, it can only tabulate how people use their search engine.

If you were asking for the real connection between hexadecimal and binary, then going back to my clarification above, one hexadecimal element encodes 16 possibilities or 4 bits, but a binary element encodes 2 possibilities or 1 bit. To encode the 8 bits of information in a byte we need 2 hexadecimal elements or 8 binary elements. So you can see that binary or hexadecimal editors may be used interchangeably since they represent the same data, just in different views.

1

They're called "binary" because they let you change individual bits.

The UI usually works in hex by default because it's more convenient - e.g. ffffe0007d13e650 takes less space on the screen than 1111111111111111111000000000000001111101000100111110011001010000. (That's an actual address from a debugging problem, not a made-up example.) It's easier to "see" things like ascii or Unicode characters in the hex code, too.

But most of them will switch to showing you binary bits if you really want them to.

(Why do we drive on the parkway but park on the driveway? It's just words. English is often strange.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .