Почему шестнадцатеричные редакторы называются бинарными редакторами?

15815
Joseph A.

Шестнадцатеричный и двоичный - две разные базы. Hex, в моем понимании, просто более простая в использовании и более удобная версия бинарного файла.

Тем не менее, я часто слышу, что шестнадцатеричные редакторы являются двоичными редакторами. Если вы ищете «бинарный редактор» в Google, вы получите шестнадцатеричные редакторы.

80
Шестнадцатеричное - это несколько читабельное представление двоичных данных. Salman A 8 лет назад 2

12 ответов на вопрос

184
Steven

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.

84
Lightness Races in Orbit

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.

55
Margaret Bloom

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.

Хорошие примеры, показывающие разницу. На самом деле, видя их рядом, гекс выглядит намного лучше DrZoo 8 лет назад 1
@DrZoo Если вы не имеете дело с битовыми полями, в этом случае двоичное представление намного лучше! https://en.wikipedia.org/wiki/Bit_field. misha256 8 лет назад 1
misha256: честно говоря, когда я смотрю на hex - я вижу бинарный файл. Я читаю «f», но мой мозг сразу говорит «1111». Это похоже на просмотр матрицы в компактном виде. :) tdrury 8 лет назад 6
+1 за акцент на «Бинарный как сырой, а не базовый два» Kelvin 8 лет назад 4
@tdrury хорошая мысль, я полагаю, через некоторое время вы просто начинаете «видеть» то, что нужно видеть, независимо от того, как это выражено. Хаха, да, Матрица! Напоминает мне парня, с которым я ходил в школу, который счастливо кодировал машинный язык в шестнадцатеричном или десятичном виде и мог свободно конвертировать между ними. Он знал все коды операций наизусть и видел битовые поля и другие структуры упакованных данных, как будто это был его первый язык. Имейте в виду, что это были Commodore 64 дня (гораздо более простые дни), но все же впечатляющий талант. misha256 8 лет назад 5
Я не согласен, что разделение падает так же чисто, как это. шестнадцатеричный редактор * - это * двоичный редактор, потому что двоичный файл означает не только базу, в которой он визуально представлен, но и то, что изменяется или читается за кулисами. Я думаю, что ваш ответ будет более точным, если вы пометите два блока как «Отображение двоичного редактора (в двоичном формате)» и «Отображение двоичного редактора (в шестнадцатеричном формате)». ErikE 8 лет назад 0
@ErikE Правда. Я использую ваши ярлыки, если вы не возражаете. Margaret Bloom 8 лет назад 0
Браво! Мне также приходит в голову, что верхний мог бы также иметь полезные шестнадцатеричные адреса слева. И то, и другое, конечно, может отображать и редактировать текстовый файл ... ErikE 8 лет назад 0
14
DavidPostill

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.

Также обратите внимание, что, хотя Base 64 может показаться даже более простым для запоминания, мы придерживаемся Hex, потому что он обладает хорошим свойством отображения 2 символов ⇒ 1 байта. PythonNut 8 лет назад 3
8
jlliagre

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
infixed

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.

5
LawrenceC

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.

3
Burgi

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.

2
AnrDaemon

Самые ранние двоичные редакторы, которых я знаю, также были дизассемблерами. Это означает, что возможность редактирования была побочным продуктом при разборке и исправлении исполняемого двоичного файла.

Хорошим примером такого приложения является Hiew.

Собранный код (инструкции ассемблера) часто представляется в виде шестнадцатеричных строк. Я думаю, что здесь возникает современная путаница. Люди просто не знают, с чем имеют дело.

2
Mike Gillis

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.

Да, но многие файлы данных также являются двоичными. Они экономят место и перевод, когда читаются соответствующим приложением. Кроме того, даже текстовые файлы часто шифруются или сжимаются, превращая их в двоичные файлы. Joe 8 лет назад 0

Похожие вопросы