Jump to content
  • Advertisement
Sign in to follow this  
Angidmench

Simple data type question

This topic is 3646 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm reading this book, it says that bits have two values 0 and 1. Now it says byte is 8 bits long. But it has a range of 0 to 255. I don't really see how 8 bits is equivalent to storing 256 possible values. If a bit only has 2 values, and a byte is 8 bits.. wouldn't it be 8 times 2... 16? This makes me feel pretty stupid, not grasping simple basics, but if anyone would help explain it.. in a way I could understand. I'd be grateful.

Share this post


Link to post
Share on other sites
Advertisement
Someone can undoubtedly give you a better explanation but basically, since each bit's value is independent of the others it is 2^8 (256) not 2*8(16). Anyone else with more depth?

Share this post


Link to post
Share on other sites
Think of it this way: The number of values you can store with a number of bits is just the number of different combinations you can achieve with those bits.

For example, with 1 bit you have 2 combinations: 0 and 1
With 2 bits you have 4: 00,01,10,11
With 3 bits, you have 8: 000,001,010,011,100,101,110,111
With 4 bits, you have 16, and so on and so on

Generally with n bits you have 2^n different values. So for 8 bits you have 2^8=256.

Share this post


Link to post
Share on other sites
Think about counting in decimal you have the digits 0-9(10 digits). If you have an 8 digit number you can count higher than 80(8*10) right?
In fact you can count to 10^8.
In this case it is the same thing except you only have 2 digits.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!