Jump to content
  • Advertisement
Sign in to follow this  
willthiswork89

bits, bytes bite! help

This topic is 4595 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

okay im stepping up to the plate of wonderful SDL, i got it set up and my tutorial site is code3d but heres my problem, i look at the intro and i see this newly seen byte-> bytes andf bits. can anyone explain them? i dont know hex so dont go hexing me please. oh yea and its c++

Share this post


Link to post
Share on other sites
Advertisement
Your computer stores information in memory as numbers. The smallest amount of information it comprehends, a bit, can define 2 numbers (0 or 1, usually). A byte is a sequence of 8 bits, which together can define 256 numbers.

Integers, or whole numbers, in your computers memory are probably stored as 32 bits, or 4 bytes. They can define a range of 4294967296 numbers. The number of bits or bytes a piece of information takes up determines its accuracy.

In your computer's memory, 1024 bytes together form a kilobyte, 1024 kilobytes form a megabyte, and 1024 megabytes form a gigabyte.

Hope some of that helps.

-Twilight Dragon

Share this post


Link to post
Share on other sites
Think of bits as switches.
each bit can be 0 (off) or 1 (on).
1 byte = 8 bits (this is just how they designed).
if the byte 'a' is: 0011 0110 (off off on on off on on off)
byte 'b' can be: 0011 0111 (off off on on off on on on)
Each byte has a unique order of 0s and 1s (or: each byte is a unique order of 0s and 1s), so if we do 2 in power of 8, we can see that there could be only 256 different bytes (0-255).
Bits are the "switches" that make a byte.

does it help?
pex.

Share this post


Link to post
Share on other sites
yea i suppose so how can i form my own byes and bits? and then later access cirtain parts of a byte? like say

byte1[] = { 1, 0, 1, 1, 0, 0, 1, 0 }

can i do

int mybit = byte1[1];

or hows that work?

Share this post


Link to post
Share on other sites
Quote:
Original post by willthiswork89
yea i suppose so how can i form my own byes and bits? and then later access cirtain parts of a byte? like say

byte1[] = { 1, 0, 1, 1, 0, 0, 1, 0 }

can i do

int mybit = byte1[1];

or hows that work?


There is virtually never a reason to do that, with the possible exception of projects like OSes, drivers and other things which require low-level programming.

Share this post


Link to post
Share on other sites
As far as I know there are two ways to directly access bits in C/C++: using bitwise logical operators (you know, |, &, ^) and using bit-field (a sort of struct, you will need to read your C/C++ reference manual). I can imagine two or three situations where this could be needed, but they rarely happen. What are you trying to do?

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!