2.2 Programming Fundamentals Flashcards
Operators
Special characters that perform specific functions
Common arithmetic operators
Addition
Subtraction
Multiplication
Division
Exponentiation
Quotient
Remainder
Exponential Operator
**
to the power of e.g. X**3
= X cubed
Quotient Operator
DIV
gives whole number product of division
e.g. 20 DIV 3 = 6
Remainder operator
MOD
gives remainder product of division
e.g. 20 MOD 3 = 2
What rule do computers follow?
BODMAS
Assignment Operator
’=’
assigns values to variables
Comparison Operator
Compare left hand expression to right hand expression
Common Boolean Operators
AND
OR
NOT
What does each boolean operator have?
Logic Gate
Logic Gate
Receive binary data, apply a Boolean operation, output a binary result
Has a truth table -> shows the possible input combinations and corresponding outputs
AND gate
Take 2 inputs, give 1 output
If both inputs are 1, the output is 1
If not, output is always 0
OR gate
2 inputs, give 1 output
If at least one of the inputs is 1, output is 1
If not, input is 0
NOT gate
1 input, 1 output
Output value is opposite to input value
5 main data types
Integer
Real
Boolean
Character
String
Using the correct data type makes code more efficient + robust
Data type: Integer
Whole number
‘int’
Data type: Real
Decimals
‘real’
Data type: Boolean
Can take one of two values: e.g. true or false
‘bool’
Data type: Character
A single letter, character, symbol
‘char’
Data type: String
To represent text
‘string’
Size of integer
2 bytes
Size of real
4 bytes
Size of boolean
1 byte
Size of character
1 byte