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 trialJeremy Heil
2,424 PointsHaving trouble understanding the concept...
00000111 = wouldn't this equal 8? Not sure here
1 Answer
Alex Koumparos
Python Development Techdegree Student 36,887 PointsHi Jeremy,
Nope, this equals 7.
Imagine that above every digit in your sequence is the magnitude of the units. We do this in our heads with decimal but to make it explicit, the number 382 is like this:
100s | 10s | 1s |
---|---|---|
3 | 8 | 2 |
So we have 3 hundreds, 8 tens, and 2 ones, or 3 x 100 + 8 x 10 + 2 x 1.
The principle is the same, regardless of the base, so for binary we see the following:
128s | 64s | 32s | 16s | 8s | 4s | 2s | 1s |
---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |
Thus we have 1 four, 1 two, and 1 one, which can also be expressed as 1 x 4 + 1 x 2 + 1 x 1.
A handy mental trick to remember is that anytime you see a binary number that only has a single one in it, that number is going to be exactly a power of two. Anytime you see a binary number that is a sequence of all 1s from some position all the way to the right (e.g., in your case 1 starting in the 4s column and going all the way to the 1s column), that number will always be 1 less than an exact power of 2.
Hope that clears everything up
Cheers
Alex
Jeremy Heil
2,424 PointsJeremy Heil
2,424 Pointsthanks a lot alex! very helpful.