User Tools

Site Tools


haas:fall2019:c4eng:projects:bcf0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
haas:fall2019:c4eng:projects:bcf0 [2019/09/30 19:07] wedgehaas:fall2019:c4eng:projects:bcf0 [2019/10/05 20:16] (current) – [Method 2: bitwise AND the place values] wedge
Line 183: Line 183:
 NOTE that I have only taken us out to 8-bits. You may need to extend this to incorporate all the allowed values for this project. NOTE that I have only taken us out to 8-bits. You may need to extend this to incorporate all the allowed values for this project.
  
 +====Using Arrays====
 +Depending on the approach taken, you might have a need to store each of the bits for later display (for example, if you produce the bits in reverse order to the manner you wish to display them).
 +
 +An array is like a regular variable, although instead of being able to store exactly one value, it acts as a container for MANY variables (all of the same type). We can then address each value through an offset (0 being the first slot, 1 being the second, etc.)
 +
 +===The utility of arrays===
 +First, we need to identify a need; just as we needed to do with loops.
 +
 +Let's say we had the following standalone variables:
 +
 +<code c>
 +    int num1  = 13;
 +    int num2  = 73;
 +    int num3  = 26;
 +    int num4  = 57;
 +</code>
 +
 +We likely understand how to work with each of the four independent variables, but we can't exactly automate accessing them, such as through a loop.
 +
 +This is where an array can come in handy. Witness, the equivalent storage of numbers using an array:
 +
 +<code c>
 +    int num[4]; // declare a 4 element integer array
 +    num[0]  = 13;
 +    num[1]  = 73;
 +    num[2]  = 26;
 +    num[3]  = 57;
 +</code>
 +
 +What value does this offer us? Well, for one, we can automate the access of the array. Let's say we wanted to display the array contents (we have to do so one element at a time):
 +
 +<code c>
 +    int index  = 0;
 +    int max    = 4;
 +    for (index = 0; index < max; index = index + 1)
 +    {
 +        fprintf (stdout, "%d\n", num[index]);
 +    }
 +</code>
 +
 +Perhaps an array can be of some use in this project?
 =====Submission===== =====Submission=====
 To successfully complete this project, the following criteria must be met: To successfully complete this project, the following criteria must be met:
haas/fall2019/c4eng/projects/bcf0.1569870457.txt.gz · Last modified: 2019/09/30 19:07 by wedge