Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Digital Literacy Computer Basics Computer Basics Binary

What number is represented by the byte 00000111?

What number is represented by the byte 00000111? and why?

3 Answers

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,076 Points

This is a much better question than the one you asked earlier, and I will be glad to explain it to you.

This is going to be a long winded response so sit back, sip some tea and take this slow!


Normally when humans count we do so through the use of numbers represented like so: 19, 8, 345, 10. These numbers are what we call base 10 numbers. We call them base 10 because we formulate the values of these numbers by counting out how many 10s are in the value. We accomplish this by summing the values as they are multiplied by powers of 10, whose powers are represented by the values position. The position starts at 0, and is increases from right to left. Let's use 345 as an example of how to calculate a base 10 number.

We start off by figuring out the positions of each number:

  • 5 is in the lowest position, position 0
  • 4 is in the 2nd position, position 1
  • 3 is in the highest position (in this given number), position 2

So now we calculate each position like I specified above, by multiplying the values by a power of 10 whose power is influenced by that values position!

Tip: When you see me say 10 to the power of something I will write it as so: 10 ^ something this basically means that we are multiplying 10 by itself something amount of times. So for example. lets pretend I say 10 to the 3rd power, I am really saying: 10 ^ 3 = 10 x 10 x 10 = 1000

  • 5 : 5 x 10 ^ 0 = 5 x 1 = 5
  • 4: 4 x 10 ^ 1 = 4 x 10 = 40
  • 3: 3 x 10 ^ 2 = 3 x 100 = 300

Now we add all the values up and we get 300 + 40 + 5 = 345. That is how humans count. Now that you are familiar with that let's use the same concept to solve for your answer.


Computer do not count like humans they don't use base 10, instead they use base 2, because of this the only values a computer can use to represent a number is: 0 and 1 (which is 2 values when we start counting at 0). So when you see the binary number: 101101 you know that you need to find out what is value is by computing the 0s and 1s, like we did with base 10. The only difference here, is that we will be using 2 ^ something since we are in base 2!

So let's find out the positions of that number starting from the right:

  • 1 is in the lowest position, position 0
  • 0 is in the 2nd position, position 1
  • 1 is in the 3rd position, position 2
  • 1 is in the 4th position, position 3
  • 0 is in the 5th position, position 4
  • 1 is in the highest position (at least for this number), position, 5

Now let's calculate them in the same order:

  • 1: 1 x 2 ^ 0 = 1 * 1 = 1
  • 0: 0 x 2 ^ 1 = 0 * 2 = 0
  • 1: 1 x 2 ^ 2 = 1 * 4 = 4
  • 1: 1 x 2 ^ 3 = 1 * 8 = 8
  • 0: 0 x 2 ^ 4 = 0 * 16 = 0
  • 1: 1 x 2 ^ 5 = 1 * 32 = 32

Now we add them up: 32 + 0 + 8 + 4 + 0 + 1 = 45

So the binary number 101101 is the binary representation of the number: 45!

Using this same logic do you think you can solve: 111?

If you can't the answer is equal to: 5 + 2

michaelcodes
michaelcodes
5,604 Points

Very nice answer, in depth and thorough

Dane Parchment
Dane Parchment
Treehouse Moderator 11,076 Points

Thank you! I was hoping I could explain it without making it too confusing!

michaelcodes
michaelcodes
5,604 Points

Hi there, the value would be 7. When reading a byte such as this you read from right to left. So we begin counting with the first 1 in the 00000111. An easy way to view the counting system is each 0 means to ignore the value and each 1 means we want to add the value. As we read from right to left each number we move over is assigned a value 2* greater.

The first 1 is going to be added as a 1. (1*1), the second 1 is going to be added as 2 (1*2), and the third 1 is going to be added as 4 (1*4). Now since the rest of the values are 0 we can ignore them and don't need to do anything. That gives us a total value of 7.

It is somewhat difficult to explain this, so to show the pattern I will give the example of if the number was 11111111 We would add the values as:

1*1 = 1
1*2 = 2
1*4 = 4
1*8 = 8
1*16 = 16
1*32 = 32
1*64 = 64
1*128 = 128

Add all these together and we get 255 as the value for 11111111.

I hope this helps if you have any other questions don't hesitate to ask!

Edit: I tried to make my response simplified, See Danes response for a much more thorough and well explained answer... Hats off to you Dane great answer!

lauralouise
lauralouise
14,853 Points

picture binary like working on an abacus -- each column represents a number that gets added together. the zeroes at the front represent empty columns so you can just ignore them and each column read right to left indicates double the value of the column before. -- there is a 1 (or a "yes") in the column that represents 1, a 1 (yes) in the column that represents two, and a 1 (yes) in the column that represents four.: 111 (4)(2)(1)

4+2+1=7