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:
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:
- 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
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
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 ;)