views:

494

answers:

8

Why is it that if you open up an EXE in a hex editor, you will see all sorts of things. If computers only understand binary then shouldn't there only be 2 possible symbols seen in the file? Thanks

+11  A: 

The hexadecimal values are interpreted binary values in memory. The software only make it a bit more readable to human beings.

Klaim
Ok so then there is actually 8 * more stuff, its just that it makes an ascii and therein hex version of the binary?
Milo
No, usually a byte will be represented by 2 hex values (4 bits to a HEX char) that can be converted directly to binary. Converting to ASCII would result in a lot of values that couldn't be rendered, also, it wouldn't be in HEX...
Chris Thompson
@user146780: Each hexadecimal digit is worth four binary bits. That's two place values to the byte. For example, the ASCII code for upper-case J is "4A." Most hex editors will also show printable characters if they exist in the code.
Max E.
Thanks everyone :-)
Milo
+1  A: 

Each character (byte) in the file represents 8 bits (8 ones or twos). You don't see bits, you see bytes (and larger types).

UncleBens
OK I see now, :-p
Milo
Except when displayed in a hex viewer as in the question, each hex digit represents 4 bits of the binary file.
Clifford
+21  A: 

You're confusing content with representation. Every single file on your computer can be represented with binary (1s and 0s), and indeed that's how it's generally stored on disk (alignment of magnetic particles) or RAM (charge).

You're viewing your exe with a "hex editor", which represents the content using hexadecimal numbers. It does this because it's easier to understand and navigate hex than binary (compare "FA" to "11111010").

So the hexadecimal symbol "C0" represents the same value as the binary "11000000", "C1" == "11000001", "C2" == "11000010", and so on.

Michael Petrotta
A: 

There are only two possible states. What you're seeing is larger patterns of combinations of them, much in the same way that the only things sentences are made of are letters and punctuation.

Ignacio Vazquez-Abrams
+3  A: 

This character A you see here on the screen is just a pattern made of ones and zeros. It's how we all cooperate by all the standards that make all ones and zeros making patterns ending up on the screen understandable.

The character A can have the value 65. In binary this is 0100 0001 but on the screen it might be the pattern

   ##
  #  #
  ####
  #  #
  #  #

In a exe file a lot of stuff is stored in various formats, floats, integers and strings. These formats are often used as they will easily be read directly by the computer without further conversion. In a Hex editor you will often be able to read strings that happen to be stored in the exe file.

In a computer everything's binary

epatel
+3  A: 

Computers don't only understand binary, that's a misconception. At the very lowest, lowest, lowest level, yes, data in digital computers is a series of 1s and 0s. But computer CPUs group those bits together into bytes, words, dwords, qwords, etc. The basic unit dealt with by a modern CPU is a dword or a qword, not a bit. That's why they're called 32-bit or 64-bit processors. If you want to get them to work with a single bit, you pretty much end up including 31 or 63 extraneous bits with it. (It gets a bit blurry when you start dealing with flag registers.)

Digital computers really came into their own as of 8-bit processors, so hexadecimal became a very useful display format as it succinctly represents a byte (8 bits) in two characters. You're using a hex editor, so it's showing you hex, and because of this early byte-orientation, it's showing you two characters for every 8 bits. It's mostly a display thing, though; there's little reason it couldn't show you one character for every 4 bits or four characters for every 16 bits, although file systems generally work on byte granularity for actual data (and much, much larger chunks for storage allocation granularity -- almost always 4k or more).

T.J. Crowder
A: 

Don't forget that about operating system and disk file sytem. They are may only use files in their formats. For example executable files in win32 must begin with PE header. Operation system loads exutable in memory and transfer control, assort api-instructions in the exutables and so on...The low level instructions executes by CPU, for that level instructions already may be a sets of byte.

Victor
A: 

So I am going to give a layman answer here. What others suggested above is correct, you can read binary through Hex representation. Most data is saved in round number of bytes anyway. It is possible that e.g. compression algorithm computes a compressed representation in some odd number of bits, but it would still pad it to a full byte to save it. And each byte can be represented as 8 bits or 2 hex digits.

But, this may not be what you have asked. Quite likely you found some ascii data inside the supposedly binary data. Why? Well, sometimes code is not just for running. Sometimes compilers include some bits of human readable data that can help debugging if the code were to crash and you needed to access the stack trace. Things like variable names, line numbers etc.

Not that I ever had to do that. I don't have bugs in my code. Thats right.

Nikola Jevtic