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 trialChris Faulkes
1,532 PointsWhat number is represented by the byte 00000111? I keep thinking its 6, but i have no clue :(
Binary looks soo easy but with my thought process, Nope!
1 Answer
A X
12,842 PointsTry watching the counting program run on this page: https://www.mathsisfun.com/hexadecimals.html using binary. The blue dots to the right of the binary numbers represent the number: so 00 00 00 01 is 1 blue dot or the number 1 in binary. It's a much more visual way of seeing a computer count by 1.
Computers use a more complicated system to count than we do since they only have 0 and 1 to work with. So the computer uses an octet (8) of 0's to "count" (PS if you want to know why an octet I'm happy to explain below). The octet looks like this (I added spaces to read it more easily): 00 00 00 00.
A 0 in computer counting means the number 0 but it can also be thought of as the "off" position. So the computer doesn't do anything when it encounters a 0 in the counting octet. A 1 in binary is more like an "on" position than anything else. So the 1 or "on" position in the octet means different things depending on where the 1 is in the octet. The computer's way of counting is to use exponents to multiply and then add together all the "on" parts of the octet to get the value.
So for 4 examples:
00 00 00 00 is 0 because all the 1's are "off".
00 00 00 01 is 1 because it multiplies 2 times the 0 power which is 1 and all the other fields are "off" so it doesn't do anything with them...but the computer's technically adding 0 seven times and then adding the 1: 0+0+0+0+0+0+0+1 = 1
00 00 01 10 is 6 because it skips the furthest right area since it's off (and therefore is 0), it multiplies 2 times the first power which is 2, and then it multiples 2 times the second power which is 4. So 0 + 0 + 0 + 0 + 0 + 4 + 2 + 0 = 6
11 11 11 11 11 is 255 because we're multiplying all the parts of the octets by the exponents 0-7.
So 2 to the 0 power is 1, 2 to the 1st power is 2, 2 to the 2nd power is 4, 2 to the 3rd power is 8,
2 to the 4th power is 16, 2 to the 5th power is 32, 2 to the 6th power is 64, and 2 to the 7th power is 128! (Whew!) So in the order of the octet, 128 + 64 + 32 + 16 + 8 + 4 + 2 +1 = 255