Main content

# Binary & data

Computers use bits (binary digits) to represent data as ones and zeroes. Bits are the smallest piece of information a computer can store. Explore how computers use the binary number system to represent numbers, text, images, and sound with electrical signals in their circuits.

## Want to join the conversation?

- Is Binary 0 and 1 in Computers like the DNA for Humans except computers use Binary to function the data and information?(39 votes)
- Binary is more like the smallest building blocks of information (just a 1 or 0). Its how they are strung together that gives the computer instructions and may be closer to DNA since DNA gives our bodies instructions. Binary by it self seems to be closer to atoms (Building blocks).

Algorithms may also be compared to DNA since they are instructions that tells the computer what to do with the input in order to give output. Really there is no perfect comparison, life and nature are still much much more sophisticated and complicated than even the most advanced computer...so far ;-)(51 votes)

- 255 is the maximum rgb vslue in JavaScript. Why is that?(15 votes)
- with three numbers (rrr, ggg, bbb) you can describe 16 777 216, isn't it enough?

Anyway, human eye can distinguish about 10 millions colors (10 000 000), so being able to use more numbers to describe colors would be a wasteful use of memory.

Using one less wire would mean having 127 as the max number, and so having 2 097 152 colors, which is not enough(54 votes)

- Is it possible instead of making a computer with switches being either 'on' or 'off', can you make a 'three-way switch' that has 3 different settings like 0, 1, and 2?

Even better, can computers use`hexadecimal`

instead of binary? Wouldn't it be much more efficient to store information like that?(11 votes)- Computers process the binary data via electrical pulses. To represent a 0, we have no pulse, and a 1, we a pulse. If we wanted to have more numbers added, we would use different magnitudes of pulses. However, the transistors are so good they can't quite detect
*magnitudes*of pulses that well, but really can only detect the*presence*of one. To make it easier to detect the magnitudes, we could have the voltage be higher. But, if the voltage is higher, so is the energy consumption of the computer. For this reason, computers just stick to the simplest number system they can, binary.(54 votes)

- if text and photo and video converts to binary, that means everything become binary, so how computer know which is text and which are photo ?(16 votes)
- From the author:Good question! We discuss that more here:

https://www.khanacademy.org/computing/ap-computer-science-principles/computers-101/ap-cs-p-lesson-cpu-memory-and-storage/a/file-types-kinds-extensions

Basically, every file has a "header" at the top, and that header provides information about the contents of the file, like it's file type.

An application can look at a file header to determine if it understands the file type and can open it. For example, a text editing application can't open photos, so it will look at the file header, see that it's a type that it doesn't understand, and then tell the user "sorry, can't open that!". A photo editing application will look at the file header, see that it's an image type that it understands, and then render the pixels for the image.(19 votes)

- From3:50of this lecture(i.e. Text in Binary), we learned that we can assign a number to each letter (The ASCII and Unicode System).

Now one question is troubling me a lot, In ASCII letter 'A' is represented by Decimal 65 and in Binary it will be 01000001 and this binary 65 (01000001) will be stored as a letter 'A' in computers memory, to be outputted by the monitor.

But at the same time the same binary (01000001) means a numeric 65.

How does CPU know when to represent (01000001) as letter 'A' and when the number 65?

Please make it clear to me and I shall be very much thankful to you.(8 votes)- Those bits can be letters, colors, numbers, pictures, or just about anything else you can think of. It is our choice on how we interpret the data.

Often, for data files, we put some special string of bytes at the beginning of the file (a header), and also we add a file name extension e.g. .pdf, .jpg, etc. to give programs a clue on how we want them to interpret the data. However, those programs can choose to interpet that data in any way that they want e.g. you could try to display a text file as a picture (it would probably just look like a bunch of random pixels)(12 votes)

- After input is given to computer , it will store in the form of 0's and 1'S . Before displaying output how the computer knows that particular combination of binary digits related to image or text or video?(3 votes)
- Often, files containing binary data will have a "file signature" at the front of the file which gives a clue to what the data is. For example for a PNG image file the first 8 bytes are:

The first eight bytes of a PNG file always contain the following values:

(decimal) 137 80 78 71 13 10 26 10

(hexadecimal) 89 50 4e 47 0d 0a 1a 0a

(ASCII C notation) \211 P N G \r \n \032 \n

So an image program could look at a file with this signature, and know that is probably a PNG file. However, you could still open that file up in a text editor and display it as text (most of it, other than the file signature would look probably look like random text), or you could try to play it as an audio file (it would probably sound like static).

Some programs, will just give you an error message, if it looks for a file signature and doesn't find anything that it recognizes.(17 votes)

- They say how to read binary, but how exactly does somebody write this? lets say I wanted to represent the number 44? How would I do that.(5 votes)
- Well it's just like writing normal base 10 numbers, but with different numbers that go into each place. Let's look at what happens when you write 44 normally:

1) First, you decide how many digits your number has by looking at whether the largest value is less than a certain place. Here, 44 is less than 10^2 or 100, so we know the number has 2 digits.

2) From there, you write the greatest place value down that's less than the value of the number. Here we would be looking at the tens place, and we put a 4 there because 5 would be 50, which is greater than 44

3) Now, we can take whatever's left (4) and assign it to the ones place. Technically, this is like you're dividing the original number (44) by the tens place (10), and seeing what comes out as a remainder.

For binary (base 2), it's pretty much the same:

1) Instead of looking at a power of 10, we look at a power of 2. 44 is bigger than 32 (2^5) but smaller than 64 (2^6), so our number has 6 digits. So far our number is ------

2) The greatest place would be a 1 in the 32-place. So so far our number is 1-----

3) We then divide by 2 (instead of 10). 44 / 32 gives a remainder of 12. This means we now write down what 12 is.

4) 12 is bigger than 8 (2^3) but smaller than 16 (2^4), so it needs 4 places. This means that the 5th place will have to be a 0. So far our number is 10----

5) The 8-place will be a 1 because it's the greatest that we're working with. So far our number is 101---

6) Then if you divide 12 by 8, you get a remainder of 4, which is our next number to consider. 4 is exactly 2^2, so honestly we can stop here because if 2^2 = 4, then we don't need any contribution from the 2^1 or 2^0 places.

7) This makes our final number 101100(10 votes)

- How do they use quantum computers that give off both a 1 and a 0 at the same time?(8 votes)
- How does the computer know whether the set of bits represents texts or images?

For example, how does the computer know whether*00111*represents the*letter G*or*the number 7*?(8 votes) - Does every coding language use and/or is made up of binary?(2 votes)
- Some coding languages are coded in language humans can interpret, but then they are compiled into computer language/binary.(4 votes)

## Video transcript

(upbeat music) - Hi, my name is Limor
Fried, and I'm an engineer here at Adafruit Industries,
and this is where I do engineering and design,
and I design circuits for fashion and music and technology. - My name is Federico Gomez Suarez, and I'm a software developer
with Microsoft Hack for Good, and I look into using technology to help solve some of the big
social problems of our times. (upbeat music) - You may have heard that
computers work on ones and zeroes, or you may have seen
scary-looking visuals like this. But almost nobody today
actually deals directly with these ones and zeroes,
but ones and zeroes do play a big role in how computers
work on the inside. - Inside a computer are
electric wires and circuits and carry all the
information in a computer. How do you store or represent
information using electricity? - Well, if you have a single wire with electricity flowing through it, the signal can either be on or off. That's not a lot of choices, but it's a really important start. With one wire, we can
represent a "yes" or a "no," true or false, a one or a zero, or anything else with only two options. This on/off state of a
single wire is called a bit, and it's the smallest piece of information the computer can store. If you use more wires, you get more bits. More ones and zeroes with more bits, you can represent more
complex information. But to understand that,
we need to learn about something called the binary number system. (calm music) - In the decimal number system, we have 10 digits from zero to nine, and that's how we've all learned to count. In the binary number system, we only have two digits, zero and one. With these two digits, we
can count up to any number. Here's how this works. In the decimal number
system we're all used to, each position in a number
has a different value. There's the one position, the 10 position, the 100 position, and so on. For example, a nine in
the 100 position is a 900. In binary, each position
also carries a value, but instead of multiplying
by 10 each time, you multiply by two. So there's the one's position, the two's position, four's position, the eight's position, and so on. For example, the number
nine in binary is 1001. To calculate the value,
we add one times eight, plus zero times four, plus zero times two, plus one times one. Almost nobody does this math
because computer do it for us. What's important is that any number can be represented with
only ones and zeroes, or by a bunch of wires that are on or off. The more wires you use, the larger the numbers you can store. With eight wires, you can store numbers between zero and 255. That's eight ones. With just 32 wires, you can store all the way from zero
to over four billion. Using the binary number system, you can represent any number you like. But what about other types of information, like text, images, or sound? It turns out that all these things can also be represented with numbers. (upbeat music) Think of all the letters in the alphabet. You could assign a number to each letter. "A" could be "1," "B"
could be "2," and so on. You can then represent
any word or paragraph as a sequence of numbers, and as we saw, these numbers can be stored as
on or off electrical signals. Every word you see on
every webpage or your phone is represented using a system like this. (upbeat music) Now, let's consider photos, videos, and all the graphics you see on a screen. All of these images are
made out of teeny dots called pixels, and each pixel has color. Each of the colors can be
represented with numbers. When you consider that a
typical image has millions of these pixels, and a
typical video shows 30 images per second, now, we're taking
about a lot of data here. (upbeat music) - Every sound is basically a series of vibrations in the ear. Vibrations can be represented
graphically as a waveform. Any point on this waveform can
be represented by a number. And this way, any sound can be broken down into a series of numbers. If you want higher-quality sound, you will pick 32-bit
audio over 8-bit audio. More bits means a higher range of numbers. - When you use a computer to write code or make your own app,
you're not dealing directly with these ones and zeroes,
but you will be dealing with images, or sound, or video. So, if you want to
understand how computers work on the inside, it all comes down to these simple ones and zeroes and the electrical signals
in the circuits behind them. They are the backbone of how all computers input, store, process,
and output information. (upbeat music)