EEET2246 - Engineering Computing 1: Course Revision Dr. Glenn Matthews Dr. Samuel Ippolito
EEET2246 - Engineering Computing 1: Course Revision Dr. Glenn Matthews Dr. Samuel Ippolito
Computing 1
Course Revision
Dr. Glenn Matthews
Dr. Samuel Ippolito
EEET2246 – Final Test Revision
• Congratulations on completing the core of EEET2246.
– The final assessment is the “Final Test” – 20%
– The laboratories accounted for 57% (Tasks – 26%, Tests - 31%) of the assessment,
whilst the tutorial quizzes contributed 23% (Quiz 1 – 8%, Quiz 2 – 15%).
– Laboratory marks will be finalised late next week, so check Canvas ‘Grades’ to
ensure all marks are consistent.
• The final test consists of both multiple choice, short- and long-answer
questions.
– An example of the test will be released on the Canvas subject webpage.
– For every multiple choice question there are up to five possible answers.
– Select the answer that is ‘most correct’.
– That is an answer which contains all relevant information, but no falsehoods.
– Multiple choice questions score a point for a correct answer and no points for an incorrect
answer. No answer scores zero.
– The marks will be stated for other question types.
– All answers are to be entered in Canvas.
– You may be required to use Visual Studio 2019 as part of the assessment.
– Ensure that your licence is current as no concessions will be given during the assessment.
– Only use Visual Studio if the questions states you should otherwise you will run out of time.
Operator Sign
Addition +
Subtraction -
Multiplication *
Division /
for ( init; condition; increment )
{
Code block statement(s);
}
Useful reference:
https://www.tutorialspoint.com/cplusplus/cpp_for_loop.htm
RMIT University © 2020 School of Engineering - E & B 8
Data Storage in Modern Computing Systems
• Although we have a large range of data types, it is very important to understand
how they are stored and manipulated in common computing hardware.
– In a typical processor, data is stored in bytes.
– A byte consists of 8 bits.
– In a binary system a bit is the smallest unit.
– Binary consists of two discrete values – logic 0 (off) or logic 1 (on).
– Thus, 4 bytes = 4 * 8 bits = 32-bits.
• A storage location (memory) consists of two parts, the data and the address.
– The ‘specifier’ (variable name used by the programmer) is actually an alias for an address.
– The data is the actual value stored at that particular location.
– Consider the following example of memory storage in an Intel Processor.
Address: 0xFFFFFFFF 7 0
Address: 0xFFFFFFFE 7 0
Address: 0x00000001 7 0
Address: 0x00000000 7 0
Operator Description
! Logical NOT. For example, (!x) will evaluate to true of x is zero. This
simply toggles the Boolean value
&& Logical AND. For example, (x > 4 && y <= 10) will evaluate to true if
x is greater than four and y less than or equal to ten.
|| Logical OR. For example, (x > 10 || y < 10) will evaluate to true if
either x is greater than ten or y is less than ten.
do
{
Code block statement(s);
} while ( condition );
Index 0 1 2 3 4 5 6
0 1 2 3 4 5 5 1
1 5 6 7 8 4 6 3
2 9 10 11 12 9 7 0
3 2 1 44 6 7 9 77
4 1 4 2 3 6 8 9
• To access array elements the programmer needs to use two indices and the
array name.
– To access a value at row 3, column 5 in array twoD the following notation could be used
(assuming tableValue has been defined):
tableValue = twoD[3][5]; // Access row 3, column 5.
– If we create a pointer variable called ‘ip’ and ‘ip’ contained the memory address of a variable ‘y’,
then it is said that: “ip points to y”.
– Pointer variables are declared using the following syntax:
data‐type * var‐name;
– data-type determines what type of data the pointer will be “pointing to”.
– var-name is the C++ identifier used to name the pointer.
– Another method to interpret the ampersand operator is remember that & can be
thought as “returns the address of…”
– The & operator is a unary operator.
– That is, it takes only one argument, which in this case is the variable the programmer wants
to know the address of.
– Another method to interpret the * operator is remember that * can be thought as “the contents
at address…”
– Similar to the & operator, the * in also an unary operator.
– Put another way, this example assigns the value 101 to the variable whose address
is p.
– When using pointers it is often advantageous to draw a memory map of the
program statements.
Program Execution
• Using either pointer arithmetic or the array index, identical elements in array
“str” can be accessed.
– If the programmer needs to access the 5th element in the array “str” either method can be used:
str[4] = 'r';
*(p1 + 4) = 'r';
– Parenthesis are required when using the pointer as the * operator would first find
the value pointed to by p1 and then add 4 to it.
– Each of the arguments are copied to their matching parameter in the function
variable list. This is also known as “passing by value”.
– After this code segment has finished the variable i is no longer available.
– C++ places the variable i in the “stack” when the code block executes, but deletes
it once execution has finished.
– The “stack” is a portion of computer memory used to store temporary data including return
addresses of functions and variables.
– In standard ‘C’ all variables should be defined at the start of the function.
next level up
local scope main()
– The local scopes live within the ‘sea’ of the global scope.
– Only a higher level scope can reach down into the lower levels and access all
variables below it.
– main(), func1() and func2() and all members within can access variables declared in
the global scope.
User defined 0 1 2 3 4 Variable name
type name
RMIT University © 2020 School of Engineering - E & B 29
Binary to Decimal Conversion
2 3= 8 2 2= 4 2 1= 2 2 0= 1 Decimal
Use the Base 2 system
0 0 0 0 0
2n Decimal
0 0 0 1 1
20 1
0 0 1 0 2
21 2
0 0 1 1 3
22 4
0 1 0 0 4
23 8
0 1 0 1 5
24 16
0 1 1 0 6
25 32
0 1 1 1 7
26 64
1 0 0 0 8
27 128
1 0 0 1 9
28 256
1 0 1 0 10
29 512
1 0 1 1 11
210 1024
1 1 0 0 12
211 2048
1 1 0 1 13
212 4096
1 1 1 0 14
1 1 1 1 15
• Given the unsigned decimal numbers 211 and 170, what would be the result of:
int c = 211 & 170;
Binary Representation Decimal
1 1 0 1 0 0 1 1 211
1 0 1 0 1 0 1 0 170
1 0 0 0 0 0 1 0 130
• Given the unsigned decimal numbers 211 and 170, what would be the result of:
int c = 211 | 170;
Binary Representation Decimal
1 1 0 1 0 0 1 1 211
1 0 1 0 1 0 1 0 170
1 1 1 1 1 0 1 1 251
• Given the unsigned decimal numbers 211 and 170, what would be the result of:
int c = 211 ^ 170;
Binary Representation Decimal
1 1 0 1 0 0 1 1 211
1 0 1 0 1 0 1 0 170
0 1 1 1 1 0 0 1 121
a (input) c (output)
0 1 c = ~a
1 0
• Given the unsigned decimal numbers 211, what would be the result of:
int c = ~211;
Binary Representation Decimal
1 1 0 1 0 0 1 1 211
0 0 1 0 1 1 0 0 44
• Multiply a variable by 2
var = 0x40; // existing value of variable
var = var << 1;
• Divide a variable by 8
var = 0x40; // existing value of variable
var = var >> 3;