Wiki page start changed with summary [] by Raster

This commit is contained in:
Carsten Haitzler 2015-05-28 00:02:04 -07:00 committed by apache
parent 2f5a4c6324
commit b39fb9e43d
1 changed files with 35 additions and 2 deletions

View File

@ -95,7 +95,7 @@ An example:
CPUs will do arithmetic, logic operations, change what it is they execute, and read from or write to memory to deal with data. In the end, everything to a CPU is effectively a number, somewhere to store it to or load it from and some operation you do to it.
To computers, numbers are a string of "bits". A bit can be on or off. Just like you may be used to numbers, with each digit having 10 values (0 through to 9), A computer sees numbers more simply. It is 0, or it is 1. Just like you can have a bigger number by adding a digit (1 digit can encode 10 values, 2 digits can encode 100 values, 3 can encode 1000 values etc.), So too with the binary (0 or 1) numbering system computers use. Every binary digit you add doubles the number of values you can deal with. For convenience we often use Hexadecimal as a way of writing numbers because it aligns nicely with the bits used in binary. Hexadecimal uses 16 values per digit, with 0 through to 9, then a through to f being digits.
To computers, numbers are a string of "bits". A bit can be on or off. Just like you may be used to numbers, with each digit having 10 values (0 through to 9), A computer sees numbers more simply. It is 0, or it is 1. Just like you can have a bigger number by adding a digit (1 digit can encode 10 values, 2 digits can encode 100 values, 3 can encode 1000 values etc.), So too with the binary (0 or 1) numbering system computers use. Every binary digit you add doubles the number of values you can deal with. For convenience we often use [[Hexadecimal|http://en.wikipedia.org/wiki/Hexadecimal]] as a way of writing numbers because it aligns nicely with the bits used in binary. [[Hexadecimal|| http://en.wikipedia.org/wiki/Hexadecimal]] uses 16 values per digit, with 0 through to 9, then a through to f being digits.
^Binary ^Hexadecimal ^Decimal ^
|101 |d |14 |
@ -150,7 +150,7 @@ You can even tell the compiler to make sure it has an initial value. If you don'
int bob = 42;
</code>
Once you have declared a variable, you can now use it. You can group values together in repeating sequences using //arrays// or in mixed groups called //structs// that contain a sequence of variables structured as indicated. Order is important and is maintained in memory. You can at times take advantage of this ordering for doing things like "inheritance". Arrays also have strict ordering in memory, so you can later on use pointers and simple arithmetic to walk up and down an array to access data, which is very handy on many occasions.
Once you have declared a variable, you can now use it. You can group values together in repeating sequences using //arrays// or in mixed groups called //structs// that contain a sequence of variables structured as indicated. Order is important and is maintained in memory. You can at times take advantage of this ordering for doing things like "inheritance". Arrays also have strict ordering in memory, so you can later on use pointers and simple arithmetic to walk up and down an array to access data, which is very handy on many occasions. Keep in mind that arrays (like memory) all begin at 0, so the first item is item 0, thus the last item is always size - 1.
<code c>
int bobs[100];
@ -433,6 +433,39 @@ So only compile the active code in when enabled in the compilation process.
----
==== Memory ====
Reality is that languages like C are really a slightly more convenient and portable interface to the actual machine you have. That means the CPU, it's instructions and processing as well as memory that the CPU will access one way or another. Let's visualize just some of this. Imagine memory as simply a series of boxes than can contain a number that has a value from 0 to 255 (if unsigned). To do signed values we just interpret values differently. We can have from -128 to 127 as values. When you hit the maximum value, things wrap around to the minimum. For signed and unsigned the first 128 values are the same in memory. This also is true for shorts, ints, longs and long longs, except it is the lower positive half of the range. To make life easier for computers, we will use [Hexadecimal|http://en.wikipedia.org/wiki/Hexadecimal]] to represent the numbers as raw data (no sign is implied here).
^Byte ^Value ^
|0 |01 |
|1 |2e |
|2 |fe |
|3 |00 |
|4 |1a |
|5 |43 |
|6 |aa |
|... |... |
And so on. All memory is a massive set of these bytes, one after the other. On modern systems you don't have hundreds or even thousands of these boxes, but you have millions or even billions of them. You can group them together to store more than just a small value. This is what shorts, ints, longs and long longs do (as well as floats and doubles). They simply tell the CPU to take a set of 2, 4 or 8 bytes together to be a larger value.
Let us see how a struct might map onto memory in this way. This struct:
<code c>
struct mydata
{
int number1;
char string1[15];
int number2;
double floating_point1;
char char1;
float floating_point2;
short short1;
int number3;
double floating_array[3];
};
</code>
==== Libraries ====
==== API calls ====
==== System calls ====