3 Operators & Flow Control Flashcards
Arthematic operators in C?
% operator in C?
A%B
remainder of the integer division of a/b
Microprocessor arithmetic problems?
Most simple processors cannot perform single instruction division or multiplication
Using the PIC, the XC8 compiler will break your maths down into multiple instructions, your code may no longer be deterministic!
Arithmetic: Repeat?
Division: Repeated Subtraction
Multiplication: Repeated Addition
Comments: Non-deterministic
What can it mean to be non-deterministic?
This means that it can exhibit different results for the same set of data. (Can be unaccurate)
Arithmetic: Shift?
Division: Right Shift
Multiplication: Left Shift
Comments: Only for powers of 2
Arithmetic: Newton Raphson?
Division: Newton Raphson
Multiplication: -
Comments: very fast, not accurate
Arithmetic: Shift +?
Division: -
Multiplication: Lift shift and add
Comments: Only for constants
C operator procedure?
- Expressions are usually evaluated from left to right (associativity)
- If an expression has different operators then precedence rules are applied
- Brackets may be used to form sub-expressions that override precedence
- For example arithmetic operators * / will be evaluated before + or – (think BIDMAS)
How does C deal with Boolean variables?
- Unlike some other languages C does not have a Boolean type
- C uses int
- Any non-zero value is interpreted as TRUE
- Zero is interpreted as FALSE
Relational operators in C?
Log Op: AND?
&&
Log Op: OR
||
Log Op: logical negation?
!
Logical negation?
(NOT Gate)