Sign in to follow this  
willthiswork89

bits, bytes bite! help

Recommended Posts

willthiswork89    100
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
TDragon    679
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
pex22    139
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
willthiswork89    100
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
Roboguy    794
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
cignox1    735
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
willthiswork89    100
just waning to know more about them, just like this

((unsigned int*)Screen->pixels)[ofs] = i * i + j * j + tick;

i know that im making a the pointer screen derefrence to pixels, but i really wanna know more in english whats happening here. its just for SDL

Share this post


Link to post
Share on other sites
cignox1    735
Quote:
Original post by willthiswork89
just waning to know more about them, just like this

((unsigned int*)Screen->pixels)[ofs] = i * i + j * j + tick;

i know that im making a the pointer screen derefrence to pixels, but i really wanna know more in english whats happening here. its just for SDL


What are i, j and tick? I guess you are in a double loop. Are you creating a picture with the whole set of displayable colors (as in the color picking panel in photoshop?) or something like this?

It seems to me that this code has nothing to do with bit accessing (nor byte): you are simply accessing (presumibly) RGBA surface pixels throught a unsigned int pointer. Each pixel will have a i*i+j*j+tick color. Probably you're doing something like:

int ofs = 0;
int tick = 0;
for(int i = 0; i < something; i++)
{
for(int j = 0; j < somethingelse; j++)
{
((unsigned int*)Screen->pixels)[ofs] = i * i + j * j + tick;
ofs++;
}
}



And tick probably changes with time?
Can you post some more code?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this