• Several types:
– Relational
– Arithmetic
– Assignment
– Logical
– Bitwise
ECET 209 Purdue University 2
Assignment Operator
• Modulus
• Increment
• Decrement
250 + 10 = 260
Right?
5 / 2 = 2.5
0 – 1 = -1
WRONG!!
ECET 209 Purdue University 6
250 + 10 = 4
5/2=2
0 – 1 = 255
• 8 Bit Processor
• Non-Floating Point
• Signed vs. Unsigned
128
64
32
16
1
ECET 209 Purdue University 9
8 Bits
128
64
32
16
1
ECET 209 Purdue University 10
8 Bits
128
64
32
16
8
4
2
1
1 1 1 1 1 0 1 0 250
0 0 0 0 1 0 1 0 + 10
1 0 0 0 0 0 1 0 0 260
128
64
32
16
8
1
1 1 1 1 1 0 1 0 250
0 0 0 0 1 0 1 0 + 10
1 0 0 0 0 0 1 0 0 260
64
32
16
8
4
2
1
1 1 1 1 1 0 1 0 250
0 0 0 0 1 0 1 0 + 10
1 0 0 0 0 0 1 0 0 260
4
2048
1024
512
256
128
64
32
16
8
4
2
1
0 0 0 0 0 0 0 0 1 1 1 1 1 0 1 0 250
0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 + 10
0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 260
2048
1024
512
256
128
64
32
16
8
4
2
1
0 0 0 0 0 0 0 0 1 1 1 1 1 0 1 0 250
0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 + 10
0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 260
5 / 2 = 2 not 2.5
• For example
2 * 2.5 = 5
0 – 1 = 255 not -1
Sign Bit
64
32
16
8
4
2
1
ECET 209 Purdue University 20
Signed vs. Unsigned
Sign Bit
64
32
16
8
4
2
1
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 -1
1 1 1 1 1 1 1 1 -1
• To declare a variable
– Provide the data type
– Provide the variable a name
For Example:
unsigned char number_of_dogs; // …
number_of_dogs
DDRC = 0xFF;
}
ECET 209 Purdue University 28
Multiple Declarations
C = 5 / 9 * ( F – 32 )
C = 5 / 9 * ( F – 32 )
Why?
Integer Math
ECET 209 Purdue University 34
Intermediate Values
C = 5 / 9 * ( F – 32 )
Why?
C = 0 * ( F – 32 )
Anything multiplied by 0 is 0.
ECET 209 Purdue University 35
Intermediate Values
ECET 209
132 / 9 = 14.667
Purdue University 36
Intermediate Values
i++; // same as i = i + 1
j--; // same as j = j - 1
For example
degree_F = PINA;
A B Y=A*B
0 0 0
0 1 0
1 0 0
1 1 1
A 0 0 1 1
& B 0
Y=A&B 0
1
0
0
0
1
1
^
ECET 209 Purdue University 42
Digital Logic Review
0 1 1 0 0 1 1 0
0 1 1 0 0 1 1 0 0 << 1
0 1 1 0 0 1 1 0
0 0 1 1 0 0 1 1 0 >> 1
Source: Barnett, Cox, and O'Cull Embedded C Programming and the Atmel AVR