In this section we will be following on from the previous one, using the variables that can now store our data and put them in expressions to manipulate them for coding in Raspberry Pi. So, what is an expression? Well in mathematics you can have an expression like 1+2=3, and that can be broken down into 1,2,3 and the operators + and =. In C though we can do a lot more than that, we can compare values and set true and false statements to make decisions, we can work with the binary data with numbers instead of decimals, there are many other things we can do that I will show you throughout this course.
If you look at the workshop page for this section I've created reference table of the operators you will find in C, as well as how to use them and what they mean. So, let’s have a look.
Now the operators I have listed are broken down into categories, the first 2 of which are very similar to what you would find in maths, we Arithmetic and Comparison. We have already used Assignment, we also have Addition, Subtraction, multiplication, division and Modulo like you do in mathematics. But now you also can use Increments and Decrements which are like say a=a+1 or a=a-1 so all it does is raise or decline the value by 1. Comparisons are quite similar, we have equal to and not equal to, less than, greater than, etc.
Next is Logical which works with true or false values. So not A would be true if A was false, A and B is only true if both are true and A or B is true if one or the other or both are true.
Bitwise is where we work with the binary value with the numbers, so if you don't under binary there is a great tutorial write by Sam on our website.
So, we have Compound next, which takes all the 0s and turns them into 1s and all the 1s and turns them into 0s.
We have AND, which takes the value in each column and if they're both 1 it gets 1, otherwise, it's 0. With OR, either or both can be 1 and you get a 1. With XOR (exclusive or), 1 or the other must be 1 but not both. Left and right shifts they just shift the number, either left or right.
Now Compound Assignment is just a shorthand way of using an assignment operator with one of the mathematical ones. So, for instances, A+=B just means A equals itself +B and the same is true for all the other mathematical operators.
And then we come to Precedents, which is the same for all the operations in maths. This explains in what order the operators are valved in. I’ve also created a reference table and I won’t go through it all now but it safe to say that the operators in higher rows get valved before the lower and left to right.
If you have any question about the video, feel free to hit up the forum and I’ll be happy to answer any questions. See you in the next section.
Makers love reviews as much as you do, please follow this link to review the products you have purchased.