Main content

## AP®︎/College Computer Science Principles

# The binary number system

AP.CSP:

DAT‑1 (EU)

, DAT‑1.C (LO)

, DAT‑1.C.1 (EK)

, DAT‑1.C.2 (EK)

, DAT‑1.C.4 (EK)

, DAT‑1.C.5 (EK)

Learn about the binary number system, a system where each digit represents a power of 2. Computers store everything in binary, using one bit for each digit. Created by Pamela Fox.

## Want to join the conversation?

- How are negatives represented in the binary system? Does the negative symbol (and other symbols and special characters for that matter) have its own binary code?(2 votes)
- To write a negative number represented in binary, we simply write a negative sign in front of it, like normal. Of course, computers can only store 1s and 0s so they cannot store a negative sign. Instead, computers can either use a single bit to represent a positive/negative sign, or use 2's complement representations.(7 votes)

- Oh so we multiply each number by 2?(2 votes)
- Powers of 2, yes - after which you calculate the cumulative sum. Therefore, if we have the bit string 1101, then you can calculate the decimal equivalent through...

1 * 2^3 = 1 * 8 = 8 [Most significant bit]

1 * 2^2 = 1 * 4 = 4

0 * 2^1 = 0 * 2 = 0

1 * 2^0 = 1 * 1 = 1 [Least significant bit]

The cumulative sum is 8 + 4 + 0 + 1 = 13. This would be the process for a bit string of any length n. If you multiply each bit by 2 and take the sum you will derive an incorrect answer, so be careful!(1 vote)

- How we can represent 53426 into binary numbers??(1 vote)
`53426`

= 2^15 + 2^14 + 2^12 + 2^7 + 2^5 + 2^4 + 2^1

= 1*2^15 + 1*2^14 + 0*2^13 + 1*2^12 + 0*2^11 + 0*2^10 + 0*2^9 +

0*2^8 + 1*2^7 + 0*2^6 + 1*2^5 + 1*2^4 + 0*2^3 + 0*2^2 +

1*2^1 + 0*2^0

= 1101000010110010(2 votes)

- binary is best for storing large numbers,yes?(2 votes)
- Not really. Binary representations of numbers are longer than base-10 representations. However, we can only store binary data in electronics.(0 votes)

- *Humming intesifies(1 vote)
- At1:53, she put 10 in 4 digits. So, we take a number and see how many of each number is in it. So, is 1010 = 10000?(1 vote)
- 5:21"It took us 8 bits to represent a number that only took 2 digits to represent in the decimal system."

01010101 Uses 8 bits, but I can make it with 7: 1010101.

So if we can add 0's in the front, then can't I just say,

"It took us 8 bits to represent a number [01010101] that takes a whole 10 digits to represent [0000000085] in the decimal system."

It would be nice if the video at least pointed out that you could do it in 7... anyone with me?(1 vote)- From the author:That's a really good point. YouTube doesn't make it particularly easy to edit videos, but I'll try to edit it if I get the chance. I very much agree.(0 votes)

- how many bits are numbers over 255(0 votes)
- Any positive integer n can be stored in ceil(log2(n)) bits. Generally though, computers use 4 or 8 bytes (32 or 64 bits) to store numbers.(2 votes)

- Why does binary use the 2's, 4's etc. for place values unlike the decimal number system?(0 votes)
- It needs to use multiples of three in order to represent any number using just zeroes and ones. Say we had to represent the binary form decimal number 3. This would be 0011. If we used powers of ten instead, we could only represent the powers of ten in binary.(2 votes)

- Will I get the same answer using exponents inside parenthesis? Instead of writing (1x16)

Like this: (1x2 to the power of 4)(0 votes)- Yes, you will because the places go by powers of two you can just multiply 1 by whatever exponent the place is.(1 vote)

## Video transcript

- [Instructor] The binary number system works the same way as the
decimal number system. The only difference is what
each of these places represents. This is a four digit binary number 1010. Each of these digits can
also be called a bit, since a bit represents zero or one. Now this four digit number
equals the decimal number 10. And we're going to see why. This first place, this is the ones place, just like in decimal. Now there's zero here, so that means we're gonna multiply zero times one, get the very exciting value of zero. The second place, the second bit here, that's where things get more interesting. This is actually the twos
place, not the tens place, and there's a one here, so we're gonna multiply one times two. So so far, this number equals two. The third place, the third bit, this is zero and this is the fours place. So we're going to
multiply zero times four, which is once again just zero. And we're still looking at the number two. Finally, this fourth bit here,
this is the eights place, and there's a one here. So we're gonna multiply one times eight. Add that to everything else, we end up having eight plus two, which equals decimal 10. In the decimal system, each of these places
represented a power of 10. But in the binary system, each place represents a power of two. The first bit is two to
the zero power, it's one. The second bit is two to the
power of one, the first power, which is two. The third bit is two squared,
two to the power of two, which is four. And this fourth bit is two cubed, two to the power of three, that's eight. That's the only difference
between decimal and binary, what each place represents. Once we know that, we see
what digit is in each place, we multiply them together,
and we get our final value. Now let's try to convert another binary number to decimal. We can erase this work here. And then for the number,
let's just flip the bits. Zero becomes one, one becomes
zero, zero becomes one, and one becomes zero. What do you think this equals and decimal? I'll give you a second to think about it. (hums) All right. Now let's figure it out together. There's a one in the ones place. So this so far equals one times one, that's one. There's a zero in the twos place. So we add zero times two, that's zero. There's a one in the fours place. So we add one times four, that's four. So so far, we've got four plus one, and then there's a zero
in the final place, the eights place, that's
zero times eight or zero. So we've got zero plus
four plus zero plus one, which equals five in decimal. Let's try converting a bigger
binary number to decimal. We know that this equals five. What happens if we add four more digits to the left of these four digits? Let's start by figuring out
what each place represents. One way of doing that is just
to double the previous places. So this place here is 16, this place is 32, this place is 64, and this place is 128. Another way of doing this is
to calculate the powers of two. So this place is two to
the fourth, which is 16. This is two to the fifth, which is 32. This is two to the sixth, 64. And this is two to the seventh, 128. Okay, so now we know what
each place represents. Now we can add these numbers up. We know already that
these one's equal five. We already did that. Now, let's add in what we've added here. So we have a one in the 16. So that means we're going
to add 16 to the number. Then there's a zero in the 32. So that's just gonna be zero. There's a one in the 64,
so that's going to be 64. And there's a zero in the
128, so that'll be zero. So now we've got 64 plus 16 plus five. So that's 80 plus five, which is 85 in decimal. So it took us eight bits
to represent a number that only takes two digits to represent in the decimal system. That's because each bit
represents less information, just zero or one instead of zero to nine. But it's easier for computer hardware to store binary values. So binary numbers and
the binary number system are the foundation of all computing.