Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This question already has an answer here:

Having learnt that machine code is expressed in binary (0's and 1's) and that Windows' .exe file format is an executable which according to Wikipedia:

causes a computer "to perform indicated tasks according to encoded instructions,"as opposed to a data file that must be parsed by a program to be meaningful. These instructions are traditionally machine code

Therefore when I accidentally opened a Windows executable in Notepad I was suprised to find it was a jumble of random characters. I could understand if it wasn't comprised of actual 0's and 1's (e.g. a mix of white space and some other character) but I couldn't think of why there were so many other characters. Furthermore how does Windows interpret this?

share|improve this question

marked as duplicate by Daniel Beck Dec 27 '13 at 20:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5  
Notepad will open anything, and anytime there is encoding it doesn't understand, you get weird symbols. You can open exes, DVD images, really anything. Just don't save and expect the file to still be good. –  AthomSfere Dec 26 '13 at 19:36
    
So in theory with the right encoding you could open an exe? Will have to read up on "encoding"... –  JMatt Dec 26 '13 at 19:39
2  
You can open them in decompilers or hex viewers: funduc.com/fshexedit.htm –  AthomSfere Dec 26 '13 at 19:42
15  
All files are sequences of 1s and 0s, i.e., binary. For "binary" executable files, those sequences are machine instructions. For text files, those sequences are characters in some character set. What those sequences mean and how they are to be interpreted depends on the type or purpose of a file. Notepad interprets any file it opens as text, so it displays the sequences of 1s and 0s as characters even though the sequences may have been written to the file as machine instructions. –  garyjohn Dec 26 '13 at 20:03
4  
I'd say this is actually a reasonable question from someone who just heard of the "ones and zeroes" at the heart of a digital binary computer. What you are missing is a piece of the puzzle that is how Notepad would someone "know" whether to display a file as literal digits one and zero, or as something else. It doesn't, so it does what its function is, namely display the content of the file given to it as text. That the text happens to be totally meaningless to a human isn't something Notepad concerns itself with. An enormous bundle of 0 and 1 wouldn't be any more meaningful. –  Michael Kjörling Dec 26 '13 at 21:29

8 Answers 8

up vote 81 down vote accepted

If this answer looks too long for you to sit down and read, and you just want a straightforward answer, scroll down a bit until you see the horizontal lines, which separate the answer into sections. I start very slowly, appealing to real life scenarios, and then move forward to computing concepts which assume that you understand the earlier sections. Advanced readers who already have some concept of computing can skip to the "Putting it all together" section to get the conclusions.

Analogy #1: Natural Language

Imagine this scenario: Your friend (or kid, or whatever) wants to know about the English language. This person is very inexperienced with human language overall, but somehow you can communicate with them. They ask you, "What does the English language look like?" to which you respond, in a moment of oversimplification, "English consists of sequences of letters in a 26-letter alphabet", and then you proceed to list the alphabet letters. The conversation you just had with your friend was through some sort of written communication (say, in Chinese, or some other foreign language).

Armed with this new knowledge, your friend tries to have a verbal conversation with someone. As soon as somebody says "Hello" to him, he is immediately confused: he expected this person to communicate with him using "sequences of letters in a 26-letter alphabet", but the method used to communicate with him was... mechanical waves of sound at varying frequencies? Huh??? Now your friend is completely confused. He hasn't yet made the connection that written languages in an alphabet of A-Z and spoken languages by vibrating vocal chords are two different representations of the same thing. Think about and remember the word representation; this will come up again.

This scenario describes a person with a representational misunderstanding of the spoken English language. The person expected that all English language communication should involve a transmission of a sequence of symbolic visual characters (the alphabet), but they had no idea that the same meaning can be conveyed using sound waves.

Analogy #2: Abstract Art

Let's look at it another way. Consider the following abstract art, by Arthur Dove:

abstract art

  • Think of the painting itself -- the shapes, colors, and generally the light hitting your retina -- as the raw data. This is analogous to a string of arbitrary binary data (0s and 1s) like "0111010100011010101011010101010100".

  • Now imagine what the original painter was thinking, or was attempting to convey or communicate, when he was painting this.

  • Now, imagine you and one of your friends view this painting, and consider what you and your friend are separately thinking about what this painting conveys or communicates.

The painting is a representation of something (or more than one "somethings"). But, even though the same "raw data" -- the light hitting your retina by viewing the painting -- is being processed by your brain, your friend's brain, and the brain of the original author, chances are that the three of you have at least slightly different interpretations of what the representation is of. Chances are, in fact, that each person perceives something entirely different!

This is how programs work on data. A program, or a piece of hardware that processes data, is designed to do a very specific, well-defined set of things with that data. For instance, considering the above-mentioned sequence of zeroes and ones, "0111010100011010101011010101010100", here are a few conceivable ways it could be interpreted:

  • A CPU attempting to execute this string of data might interpret it as a representation of the command, "power off".
  • A text editor trying to display this string of data might interpret it as a representation of the plain text, "hello".
  • An image viewer trying to render this string of data as an image might interpret it as a 2 by 2 square of pixels, with a yellow pixel, a red pixel, a white pixel and a green pixel, or something like that.
  • A sound player trying to play this string of data as a sound file might interpret it as a 10-millisecond pulse of high-pitched audio (say, a little "chirp" at 10,000 Hz).

Which of these possible interpretations is correct? Well, just by looking at the string of data, you can't say with 100% certainty. There might even be more than one possible interpretation. For instance, you could construct a string of binary data that, when fed into an image program, produces a beautiful image. The exact same string of binary data, when fed into a sound player, could produce a very pleasing sound. But, if the original author of the data only ever considered it in the context of an image, you'd be kind of missing the intention of the author if you spent a great deal of time considering the sound outputted by your PC speakers when playing the data with a music player, while ignoring the potential of displaying it as an image on your screen.

In each of these analogies and scenarios, there are a recurring set of themes to consider:

  • Assuming that the data was created by a human or some creature with intelligence (which includes data generated by programs which were written by humans), the person who originally organized the data into that specific string of binary bits had an intention for how it should be interpreted, according to the author.
  • Assuming that the data is being processed by some rigid program, the program that is presently interpreting the data has its own, separate view of how the data should be interpreted.
  • When the same understanding of the interpretation of the data is held by both the creator and the current person/thing processing the data, this is called conveying information -- or simply communication.
  • When there is a mismatch between the interpretation of the data between the creator and the current processor, the communication breaks down to some extent. It can either break down partially, or completely.
  • While it is true that the data itself may have interesting or useful ways of interpreting it other than the way that was originally intended by the creator, this is not direct communication; this is called information analysis -- where you make some logical deductions or inferences about things you think might be true, or must be true, based on what information you understand to have been provided by the creator. For instance, if I say "I don't like the weather outside right now", and you have a reasonable suspicion that I might dislike thunderstorms, and that the current climate outside is ripe for thunderstorms, you could have a good reason to suspect that there might be a thunderstorm outside right now, even though I didn't come right out and say that.

A conceptual understanding of language

  • What is a language?
    • A language is basically a (finite or infinite) set of pieces of information. These pieces of information are organized in a certain way, and when someone or something successfully communicates in a language, that means that the original meaning of some representation, has been duplicated, or understood, by someone or something else that later on reads the raw data.

  • What is a language not?
    • A language is not inherently tied down to any particular mode of representation of that language. When a language is represented in more than one way with different symbols (which can include, for example, characters of text, or spoken words), it is possible to "map" one representation onto another. When done successfully, you can basically consider both representations to be of the same language, insofar as they convey the same meaning.

For instance, you may know that we can represent Japanese almost equally well in all of the following ways (by "almost equally" I mean that verbal language also conveys things like intonation, sarcasm, etc. which are more difficult to convey or have to be conveyed differently in written word):

  • Japanese sign language
  • Handwritten Japanese characters (Hiragana, Katakana, Kanji)
  • A series of zeroes and ones on a computer that instruct the computer to print Japanese characters
  • A verbal language that involves vibrating human vocal chords at certain frequencies and timings to convey meaning

For our own sanity, when we learn a language, we develop a mental model that "maps" the different representations of a natural language onto one another. This is how, for instance, you can type up a paragraph of text that someone is saying to you aloud, or how you can read a passage aloud that you're reading on your computer screen as text.


What is Representation in a Digital Computing Context?

Every single piece of data that a computer processes is, at a fundamental level, in the "language" of binary -- zeroes and ones. But these zeroes and ones are represented in many, many different ways to the user when they are processed by the computer. Let's enumerate just a few of these different ways:

  • Images
  • Videos
  • Executable code (for different processors and operating systems, etc.)
  • Plain text files
  • Microsoft Word documents
  • HTML, which is basically the same as plain text, but with additional meaning on top of the ordinary meaning of plain text
  • Database files
  • etc.

Your problem is that you expect a program that represents zeroes and ones as printable text -- Notepad -- to represent the zeroes and ones as literal zeroes and ones.

So, your problem is essentially a representation problem, just as the person who was confused by the transmission of English as "spoken" sound waves.

In order to resolve this representation problem, you must understand the different ways that a computer can represent zeroes and ones, and choose the right program to represent them in the way that you want it to. But remember, no matter how magical the computer's behavior might seem, all of it is eventually zeroes and ones, and if you have the right tools, you can examine those zeroes and ones directly. It's just a matter of getting at them.

Due to the fact that most things we deal with on a day to day basis on our computers are much "higher level" than zeroes and ones (meaning, we do interesting things like display images and printed documents using zeroes and ones), the basic zeroes and ones themselves are typically not displayed by most programs. This would seem like an extremely unnecessary feature to most people. Wouldn't it be weird if, when you download a .PNG image in your web browser, instead of it being displayed as an image, it were rendered as a long string of zeroes and ones? That's why it isn't done that way, usually.


Examples of digital representation

One way to represent zeroes and ones is in a counting system called hexadecimal, which is a system that counts to 16 (it can be viewed either as counting from 0 to 15, or from 1 to 16). All hexadecimal does is it represents a string of four bits (four binary digits, that is, four values that are either zero or one) as a single character. The 16 digits of the hexadecimal alphabet are 0 - 9, A -F. If you were to think of this in terms of our ordinary decimal counting system, A would be 10, B would be 11, and so on, and 0 - 9 would be the same as they are in decimal.

To work this up to a reasonable example:

If you have a 32-bit integer, that means you have a number represented by 32 successive binary digits (zeroes and ones). Since each hexadecimal "letter" (digit, really) is composed of four binary digits, you need a total of (32 / 4 = 8) eight hexadecimal digits to represent a 32-bit integer. This allows you to represent every integer from, say, 0 to 2^32 using eight hexadecimal digits, ranging from 0x00000000 to 0xFFFFFFFF (the "0x" just means "The numbers and letters following '0x' are in hexadecimal!", that's all.)

Just to drive home the concept of representation, you could represent those 32 zeroes and ones equally well as two 16-bit numbers from 0 to 65535, or as four 8-bit numbers from 0 to 255, or as eight 4-bit numbers from 0 to 15, or as 16 2-bit numbers from 0 to 3, or as 32 1-bit numbers from 0 to 1. Representation -- it's all in how you interpret the strings of zeroes and ones. We even have representations for indicating negative numbers in binary, but they're a little complex for your level, so I won't go into them.

Similarly, English characters, like the text you are reading right now, are usually represented in binary as a series of numbers. Most often, they are represented using 8 or 16 bits, and the meaning of each digit of those bits varies depending on which encoding is used. An encoding is basically a specific way of interpreting (representing) a string of zeroes and ones in a particular way.

Here's an encoding I just made up off the top of my head. I will call it "WTF-8" (programmers will get the joke). WTF-8 is the following: Take any sequence of eight binary digits. The leftmost digit is the ones place, the next digit to the right is the twos place, the next digit to the right is the fours place, the next digit to the right is the eights place, and so on. This way you get a number from 0 to 255 using this string of 8 binary digits. In WTF-8, if the number you get from counting the binary this way results in the decimal numbers 0 to 25, assign them to a letter of the alphabet, starting from "A" at 0, and ending at "Z" at 25. If the number is greater than 25, it is an error.

I just defined a very simple encoding -- a particular way of looking at a string of eight binary digits to define the letters of the English alphabet. Ordinary printed text on a computer is not all that drastically different from WTF-8, although the number of encodings in common use is quite large, and can lead to some confusion. Some encodings also have rather complicated tricks in them, enabling them to represent many thousands of non-English characters: Chinese, Japanese, Korean, Russian, and so on.


Putting it all together

A hex editor is a program that can display any data stored in a file as hexadecimal values. Some hex editors can also display the raw binary 0 and 1 sequences. But hexadecimal is more convenient to think about, usually.

So to answer your question now that you understand your representation problem... use a hex editor, not Notepad, to view files' raw binary stream, either as binary itself, or as hexadecimal, or possibly as octal, or other counting systems (some hex editors even allow you to view the data in any arbitrary counting system!) By comparison, the only representation (encoding) that Notepad is familiar with is plain text (of various formats; primarily "ASCII" and "Windows Western" plain text encodings, although you can sometimes get it to read other representations correctly as well.)

It is critical that you understand this point: Because it's all zeroes and ones, most programs that process data in a general way, without trying to determine whether it is correct or not according to some specification, are perfectly happy to display data using the method of representation that that program was written to present to the user. So, even though an .EXE file is supposed to be executable code, you can still open it in Notepad, and it will try its best to represent the sequence of zeroes and ones within that file as printable text. Of course, it does a terrible job at it, because executables don't store native machine code as printable zeroes and ones in a human-readable encoding. Rather, there is a specific binary format, defined by the operating system and processor, that the zeroes and ones are intended to be read in, in order to be executed. This is what happens when you run notepad.exe.


Epilogue

Here's a fun experiment with incorrect representations. Some programs will let you attempt to play any bit stream as if it were a WAV file, which normally consists of listenable audio data. So, you could take the bits contained within notepad.exe, or a Word document, or even this webpage, and attempt to play it as if it were a WAV file. It'll probably sound like static to your ears when it comes out of your speakers; it may even contain interesting patterns of noise. But it won't sound like someone reading your document! That's because you're attempting to represent printable text as sound, and the two simply aren't compatible that way. (NOTE: If you try this experiment, please turn your volume down first, or you might be startled by the odd noises your music player makes :))

Oh, and just in case you thought a hex editor is the "final" or "most low-level" way of interpreting binary data: it's not! When it comes down to it, a hex editor is just one more ordinary way of interpreting a sequence of bits. There is really nothing special or mysterious about its specific choice of representation, which is usually to use hexadecimal with the Arabic numerals 0-9 and the Roman/Latin alphabet letters A-F. The "final" representation in a solid state computer is actually the electrical impulses inside the circuitry that indicate whether each transistor is "on" or "off", which, if you had a very sensitive microscope, or a computer running on a much larger scale, you could see within the computer. Well... is that actually the final representation? I'll leave that as an open question ;)

share|improve this answer
12  
This is an amazing answer. I love the analogy to human language! +1 –  mebob Dec 26 '13 at 23:23
6  
Just a couple more paragraphs and anyone can program their own EXE's in WTF-8 language :) –  jwalker Dec 26 '13 at 23:56
4  
Interesting, but the actual answer to the actual question is simpler and shorter than this. –  jwg Dec 27 '13 at 1:27
8  
This is over-answering the question. If your answer needs an epilogue, you've gone too far. –  Substantial Dec 27 '13 at 2:11
4  
@jwg The OP displayed such a fundamental lack of understanding of how computers work by even asking that question, that I felt I had to provide a comprehensive answer that goes back to the beginning. Someone with that question, phrased in that particular way, clearly knows next to nothing about computing, or even language. If you just said "Notepad reads the file as if it were text not binary; use a hex editor", he'd be like "......ok, I still don't understand" because he doesn't understand the fundamentals. –  allquixotic Dec 27 '13 at 17:22

Every file on your hard drive is a sequence of 0s and 1s. For example some file can be represented by this sequence of bits:

01000101011111110110000101101101011100000110110001100101

If you split it into 8-figure sequences, you'll get bytes. Each byte can hold a number from 0 to 255. It will look like this in binary representation:

01000101 01111111 01100001 01101101 01110000 01101100 01100101

Or like this in hexadecimal representation:

45 78 61 6d 70 6c 65

Decimal is impractical here because binary doesn't convert "nicely" (see Why does conversion from hexadecimal to binary work so cleanly?).

I said that on one byte you can save numbers from 0 to 255. That's thanks to math: we have 8 bits, each one with 2 possible states. 28 = 256. So we interpret binary 00000000 as decimal 0, binary 00000001 as decimal 1 and so on, up to binary 11111111 which is decimal 255. 256 numbers in total.

But we could also interpret it in a different way: let's say that we want to save numbers from 1 to 256. It's possible too, we just have to agree on some other (non-mathematical) way to map binary values to decimal values. There are two reasonable solutions:

  1. 00000000 is 1, 00000001 is 2 and so on up to 11111111 which corresponds to 256.
  2. 00000001 is 1, 00000010 is 2 and so on up to 11111111 which corresponds to 255 and let's assume that 00000000 is 256.

It's still one byte, but we can interpret it in many ways. We can even save signed numbers on bytes if we both agree for a correct mapping of binary values to decimal numbers they represent. Or we can say that binary values represent not numbers, but characters! That's called ASCII[1].

ASCII is a standard for mapping numbers to characters. Have a look at these ASCII tables: they describe how numbers correspond to specific characters. But remember, you have to use correct interpretation. Let's use that table to decode hexadecimal byte values to characters:

45 78 61 6d 70 6c 65
E  x  a  m  p  l  e

Clearly, it is a text file we have here. Now try to decode these bytes:

25 38 61 dd

You'll get something like this:

%8aÝ

These were not ASCII-encoded bytes, that's why we got some gibberish instead of text. We've tried to interpret them using incorrect mapping.

Notepad is a text editor. When you open a file with it, it will try to interpret it as text bytes. If they aren't text, you'll get only a result of inappropriate decoding. Not 0s and 1s, because it doesn't show bits - it shows interpretation of bytes.


[1] Actually, ASCII is just one of many codepages but it's the simpliest one and I'll use it in this answer.

share|improve this answer
    
Very detailed, accurate, technical answer. A useful contribution to this question, which is becoming a sort of community project of its own :) Upvoted! –  allquixotic Dec 27 '13 at 0:54

These answers are very long.

The simple answer is: Notepad tries to see the 0s and 1s as text, which is its job. It doesn't realize they are not text and just displays what it can, which is a big jumble of letters that make no sense.

share|improve this answer

allquixotic's answer makes an important point that I'd like to expand on a bit:

So, even though an .EXE file is supposed to be executable code, you can still open it in Notepad, and it will try its best to represent the sequence of zeroes and ones within that file as printable text. Of course, it does a terrible job at it, because executables don't store native machine code as printable zeroes and ones in a human-readable encoding.

The "zeroes and ones" which make up an executable file (or any file, or the operating system itself) are each one "bit." Eight bits form a "byte."

A character is a single symbol such as A, B, C, 1, 2, 3, !, @, #, , and so on. There are also other characters which may or may not be visible in some way: tab, null, backspace, carriage return, bell, etc.

Characters are represented using those "zeroes and ones" differently depending on the character encoding being used. A character encoding pairs some code with a character. You might have heard of ASCII, Unicode, or UTF-8; these are all character encodings.

An ASCII character is represented by 7 bits, just under one byte. The character 1 is #49 in ASCII, while 0 is #48. In order for Notepad to display your executable using an ASCII encoding starting with "01", the actual ones and zeroes of your executable would need to start with:

01100000110001
[--0--][--1--]

(Second line included for clarity)

If that same executable were to be displayed with an 8-bit extended ASCII charset, the first displayed character would be ` rather than 0.

If the display moves up into multi-byte charsets like Unicode, you start to move away from the trivially-recognized characters, and into a wide range of other possibilities. (If you add two more zeroes to the above file, for example, it would begin with in UTF-16.)

Here's the file again:

0110000011000100
[--0--][--1--][-  (7-bit ASCII)
[---`--][---Ä--]  (8-bit ISO-8859-1)
[-------惄------] (UTF-16)

As you can see, the character encoding used to display the file makes a large difference on what the result is, and has no immediately apparent connection to the underlying bits.

Now consider what would happen if some of the series of bits formed control characters when displayed in the chosen charset! Some don't display at all (such as #0, null), some modify how previous or future characters will be rendered (#8 is the backspace character, deleting the previous character on the line; #13 is the carriage return character, equivalent of pressing the "Home" key on your keyboard), and one of them (#7, bell) even tries to make an audible noise when it's printed! Add to that the possibility of a chosen font not containing certain glyphs, and you have potential for an "interesting" time when opening a non-text file in a text editor.

share|improve this answer
1  
Great answer. This really goes down into the nitty gritty of why an EXE opened in Notepad looks so funky. I purposefully avoided covering the subject in such detail in my answer because I wanted to appeal to a non-technical audience. Your answer properly completes the explanation, and is complementary to my answer. +1. –  allquixotic Dec 27 '13 at 0:53
    
u wrote "You might have heard of ASCII, Unicode, or UTF-8; these are all character encodings." <-- While apparently the unicode standard has a definition of encoding, such that it calls the character set an encoding too.blog.reverberate.org/2009/01/is-not-encoding.html It's clearer to talk about character sets and byte encodings.. See the three comments between carl and josh. Most wouldn't consider Unicode (when not followed by something else like standard or encoding), to be an encoding. Unicode when used alone,means the character set. And people don't really call that an encoding. –  barlop Dec 27 '13 at 19:47

A binary contains zeros and ones, but so does a text file, a word document and a video. How the file is encoded -- which at this point in the explanation is just a magic word -- "tells" your editor (or video player) how to read the file. Hex editors are editors which takes anything you give it and reads out actual ASCII zeros and ones or text for you.

If you want to learn more, Wikipedia is a good place to start (though I've caught flak for linking to it here in the past so I won't.) In addition you should read this: The minimum everyone should know about character encodings. If you ever pursue a tech-related career, your future coworkers and clients will thank you.

If you decide that you like reading things in hex editors try this one. Never used it myself but it seems to have good reviews.

share|improve this answer
    
I can vouch for HxD. It's the only hex editor I use. –  Andrew Lambert Dec 26 '13 at 20:11
1  
Well, now I know where to go if I ever need a hex editor. :) –  Yitzchak Dec 26 '13 at 20:18
    
-1 I can't believe he mentioned wikipedia and you're telling him to go to wikipedia to staort, and as if he never heard of it or hasn't checked wikipedia. But in his simplistic question which showed so little depth of thought, the one bit of thought or research he did was quote wikipedia. And when you write this "actual ASCII zeros and ones " you show you haven't the foggiest idea what it's about Maybe you should be asking the question on this one. Anyhow, it's actually a good question just a shame he couldn't figure out the answer with a bit of thought –  barlop Dec 27 '13 at 0:19

Short Answer: Text Editors don't speak Binary

The Binary 1 and 0 sequences you were expecting are read into the text editor in 8, 16, 24, or 32 bit long chunks (called "words"), and those words converted to individual characters.

Note also: the computer's CPU doesn't read them as individual 1's and 0's either...

Elaboration

Encodings

Various text editors are equipped for various encodings. An encoding is a way of converting binary data into human readable text.

The simplest is ASCII, which is a 7 bit encoding; pure ASCII text editors (there are a few) set the 8th bit to 0; a few very old word processors use the 8th bit to mark either hidden commands or metadata.

More complex, and while not identical, are the 3 common 8-bit character sets: Windows CP-1252, ISO-8859-1, and Macintosh Roman. Each uses 8 bits to define a single symbol. Several older ones exist, such as the MS-DOS standard CP-437, ATASCII, and KOI8-R.

Next, there are a few 16-bit encodings out there. They are little used, and now mostly historical curiosities.

Then, there are the progressive encodings, of which only Shift-JIS and Unicode have much traction. In both, a single word (usually 8-bit) is used, but if in certain ranges, a second word is added, and a much wider variety of characters is used.

Programming encoding

Computers also don't actually speak binary. They encode their instructions and data in binary. They use a word of a processor specific size (and often processor series specific encoding) to trigger instructions. Each allowed combination is called an "opcode" - and they range from a low of 3-bits wide through 32-bit wide. Most current processors use 8 or 16 bit opcodes, tho' some still use 4-bit. This isn't the same as the processor's math-width, nor the processor's bus width...

An example 4-bit opcode encoding with an 8-bit processor word (from the JAW CPU):

    NOP      0000XXXX         
    SUB      0001AABB        regAA < = $regAA - $regBB
    AND      0010AABB        regAA < = $regAA & $regBB
    OR       0011AABB        regAA < = $regAA | $regBB
    ADDI     0100AAAA        reg3 < = $reg3 + AAAA
    ADD      0101AABB        regAA < = $regAA + $regBB
    NOT      0110AABB        regAA < = !$regBB
    SLL      0111AABB        regAA <= $regAA << BB
    SETMI    1000AAAA        MemAccessReg < = AAAA
    SW       1001AABB        Memory Data at address [$MemAccessReg, $regBB] < = $regAA
    BEZ      1010AABB        if ($regAA == 0) then PC < = [$MemAccessReg, $regBB]
    BGZ      1011AABB        if ($regAA > 0) then PC < = [$MemAccessReg, $regBB]
    LDI      1100AAAA        reg3 < = AAAA
    LW       1101AABB        regAA < = Memory Data at address [$MemAccessReg, $regBB]
    SETM     1110AAXX        MemAccessReg < = $regAA
    ZERO     1111AAXX        regAA < = 0000

The A's and B's represent variables' bit locations, and the X indicates bits which are simply ignored. A program is a string of opcodes and data.

More practical modern CPUs usually use 8-bit opcodes, with certain ones grabbing the next word or two as operands (so a single instruction may be 1-3 bytes of 8-bits)

Putting them together

When your text editor looks at the opcodes, it's not reading them as "binary" but as "characters" in its preferred encoding. The compiler, however, wrote them into binary as a storage medium, so that the processor will read them an opcode word at a time. Neither interprets them as a string of 1's and 0's, but as chunks of larger size.

share|improve this answer

Having learnt that machine code is expressed in binary (0's and 1's) and that Windows' .exe file format is an executable which according to Wikipedia:

Most current computer architectures operate on whole bytes (groups of 8 bits) or multi-byte words (2 bytes for 16 bits, 4 bytes for 32 bits, 8 bytes for 64 bits), rather than single bits. Most filesystems store files in bytes. If you want to store 2 bits, 1 byte (8 bits) would be stored. If you want to store 9 bits, 2 bytes (8*2 = 16 bits) would be stored.

  • Program commands can be (and are being) encoded as a sequence of bytes.

  • English text can be (and is being) encoded as a sequence of bytes. Each letter generally takes 1 byte.

  • Russian text can be (and is being) encoded as a sequence of bytes. Each letter generally takes 1 or 2 bytes.

  • Chinese text can be (and is being) encoded as a sequence of bytes. Each letter generally takes 1 to 4 bytes.

  • Random noise can be (and is being) encoded as a sequence of bytes.

There are text files and binary files. They are both stored the same - as a sequence of bytes. There is no real technical distinction between text files and binary files. There are just sequences of bytes.

It's just that human can generally understand the content of the text files. People who don't know Chinese would have a hard time to understand the Chinese text files.

Executable files are understandable by the operating system. Like in the English and Chinese example, the Windows OS won't understand the executable file created for the Linux OS.

Your .exe file is a file. As with all files, it's stored as bytes. Just like text files, image files and audio files. So, you can try to interpret any file as text, image, audio, executable etc. You've just did that - you've interpreted the bytes that represented a program as bytes representing some text. So you see a (gibberish) "text".

You can try to interpret .exe as an image (via special programs - Paint won't open them). http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=74534&lngWId=1

You can play .exe as an audio file (via special programs - common media players won't open them). http://boingboing.net/2011/03/10/using-exe-files-to-c.html

It's all a matter of reinterpretation of bytes.

What is "GABCDEF"? Is it text? Is it gibberish? Or maybe it's a musical tab, where notes are written as letters.

To tell the viewer what is stored inside the file (what's the intended meaning of the bytes), different file formats and markers are used. And in Windows, the type of a file can be generally deduced from the file's extension (.exe, .txt, .jpg, .mp3 etc).

share|improve this answer

I like the other answers, but they aren't half long.

My simpler answer is: 1s and 0s are a figment of our imagination.

You see, when we talk mathematically, we like to call them 1s and 0s. We might better call them 'On' and 'Off'. As far as the computers are concerned, these are actually bursts of electrons moving through the system - a high voltage is 'On' and a low voltage is 'Off'. They are stored slightly differently on disk, but once they get to the processor, everything is a pattern of 'on' and 'off's - each is an individual 'bit'.

Fun fact: the processor, the brain of your computer, doesn't know what those high/lows are meant to represent. It doesn't even know that 8 bits make up a byte, just that it has to wait for 8 bits.

It then tries to match those bits to an instruction, which will then determine how many bytes will complete the instruction. So for example the instruction might call for 2 more bytes, for example "take the first number - find the memory location from that "address", and place the second byte in it", or even "add the second byte to whatever is in that address"

Another fun fact: not everything that the processor calls "memory" is what we would call memory. Sometimes, the processor can treat pixels on your screen as memory, or other devices. Sometimes it is allowed to write to these addresses, sometimes it's allowed to read - rarely, as with actual memory, it can do both.

So your computer treats these highs and lows very simplistically. It doesn't know what they are, or where they are going - they're all just addresses for instructions, or "memory" locations, or data.

Last fun fact: Take any character on this page. Here's one: 1. That number one took several instructions to show on your screen. It was probably stored as what we will call a character, 8 or 16 bits, before an instruction was received to write it to your screen. Then, several instructions looked up our "character" in a font file, which told it (after a bit of mathematics) what shapes to show on your screen. Then, another instruction pushed those shapes to a device, your graphics card, with its own processor, and its own instructions, which worked out what pixels to display, which sent it to the screen. And that's the simplified version!

At no point does the processor "understand" that those 8 or 16 bits were a letter, or what that letter was meant to represent. It is simply one program that tells it to take data, and push data.

share|improve this answer
    
Computers don't know anything in the same way that humans do. But that aside, the processor and the instructions very much do know what to do with groups of bits and bytes. The wires and switches are built to do very specific things with them. –  siride Dec 27 '13 at 2:27
    
Knowledge is an anthropomorphization, attributed to complex systems, allowing us to reason about higher-level behaviours. It no longer helps when discussing the low-level. It's like saying a switch knows when it's pressed. The switch being pressed makes a connection. A switch doesn't know what the circuit is for, who pressed the switch, or why. In the same way, a processor has a 'numbered' list of circuits it can pass data to, where 'number' means a list of bits. The transistors in a circuit do a job; the result of these compounded jobs only make sense to us as humans. –  user208769 Dec 27 '13 at 3:53
    
well, if you're going to anthropomorphize, you need to do it correctly. The CPU and the subcomponents very much much do "know" what bits and groups of bits mean, though they also allow them to pass through without any CPU-level interpretation. –  siride Dec 27 '13 at 4:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.