by Fuzzy » Thu Apr 26, 2007 11:45 pm
The basic type of variable is the bit. it is either 0 or 1.
A byte is simply a number from 0-255. You dont see it much in C or GE. It is composed of 8 bits. so a byte containing a value of zero is written:
0000 0000
Notice that I put a space in there. that is because there is a little hidden programmer joke, and it also helps make it more readable. The joke is that half a byte(bite) is a nybble (a nibble). You cannot use a nybble directly. So ignore it, other than giggling(gyggle?) about it.
A char is a special byte where the first seven bits hold the number, and the eigth bit represents plus of minus. Because of this, a char represents the value -128 to +127, a range of 255. It is an 8 bit integer.
To make a char into a byte we add 'unsigned' infront of it. like so...
unsigned char FuzzyAge = 34;
Which causes the compiler to discard the +/- and use that space to count. So fuzzy can get no older that 255.
Next we have the word, which is a 16 bit unsigned integer. If you hear people speak of the first nintendo as being 16 bit, this is what they mean. The first computers were too. if we continue the bit/nybble/byte joke, a word is a playte. Thats really getting obscure.
A signed integer ranges from -32768 to 32767. It is called a short int.
short int FuzzyScore;
Now modern computers are 32 bit systems. The joke is "dynner". think of dinner. Now go eat some.
A thirty-two bit variable with a sign (+/-) is called an int, or integer.
You have to be careful of this though, as they change it from operating system to operating system, and as computers get stronger, they raise the bit limit. An integer used to only be 16 bits. Again, they sometimes call this a word too.
The range is −2,147,483,648 to +2,147,483,647
One more type of integer is the long int. Its insanely big. 64 bits. It can handle can handle trillions of values or more.
Whats the silly term? I'm not telling you. That joke is ridiculous. Why do you even want to know? Who would know what you were talking about anyway?
Now... arrays. Arrays are collections of numbers. Think of all the letter boxes at the post office. Each has a column number and a row number. You could even have a depth number, or more. First you pick a number type, that each box will store. then, name the variable, and the in square brackets, [], you put the number of rows. if you need columns, put a second one.
int CoinType[6];
in Canada we have six types of coins. to store the number of pennies, we access the first box like this.
CoinType[0] = 0;
Fuzzy doesnt even have a penny. However, when out walking, he finds a quarter.
CoinType[3] = 1;
I chose int for the array type because it is the smallest size that is practical. If i had used a unsigned char, then I could only ever have 255 of one coin type.
Here is a 2 dimensional array.
int ScreenCopy[640][480];
So that is the integer types. Now for strings.
A string is simply an array of char!
string Name="Fuzzy";
is the same as char Name[5] = {'F','u','z','z','y'};
Thats it for strings!
Now onto floats.
Floats work just like ints, but through a esoteric process, they store the numbers decimal as well. You have float and double to play with. float is 32 bit, and double is 64 bit.
And thats it! Questions?
Mortal Enemy of IF....THEN(and Inspector Gadget)
Still ThreeFingerPete to tekdino