B&R Automation Studio Operators in ANSI C Programming
Operators are symbol that is used to perform various operations on variable, data, value, tag etc. these operators are Arithmetic operators, Assignment operators, Comparison operators, Logical operators, Bitwise operators etc. each operators have unique reserved symbol for example if we want addition of two tag value than we use arithmetic addition operators(+). For comparing two value we use comparison operators.
B&R Automation Studio Arithmetic operators in ANSI C Programming
Arithmetic operators perform arithmetical operations on numerical values or variables. these operators are addition, subtraction etc. following the list of arithmetic operators in ANSI C programming
+ addition operator
- subtraction operator
* multiplication operator
/ division operator
% modulo operator, remainder after division
above is the example of Arithmetic operators in ANSI C Programming. in this example we use (%) modulo operator for comparing value is even or odd. When value divide by 2 if the value is even than remainder is zero. if the value is odd than remainder is 1.
B&R Automation Studio Relational (Comparison) operators in ANSI C Programming
Relational operators perform Comparison of two values or variables and return a Boolean result(true or false). if the comparison result is true than result is true if the comparison result false than return false. these operators also known as Comparison operator. following the list of Relational(Comparison) operators in ANSI C programming
== equal to operator
!= not equal to operator
> greater than operator
>= greater than or equal to operator
< less than operator
<= less than or equal to operator
above is the example of Relational (Comparison) operators in ANSI C Programming. in this example we find enter value is positive or negative by using comparison operator. if the entered value is greater than 0 than value is positive if the entered value is less than zero than value is negative. Relational operators (Comparison) are often used in conditional statements (if, else if, else, switch, etc.), to control the flow of the program based on certain conditions.
B&R Automation Studio Logical Operators in ANSI C Programming
Logical Operators in ANSI C Programming Used To Combine Two Or More Boolean expressions And Evaluate Them As A Single Expression. the result of logical operator depend on use of logical operator. following are logical operator
&& logical AND operator
|| logical OR operator
! logical NOT operator
above is the example of Logical Operators in ANSI C, in this example we use all logical operator and combine three tag bool value into a single result. motor start if the pb_start set to true, and pb_stop false. NOT operator invert the condition of pb_stop.
B&R Automation Studio Bitwise Operators in ANSI C Programming
Bitwise Operators in ANSI C Programming Used To perform operations on individual bits of data. these data are numerical value(integer data type). low level bit operations. following are the bitwise operators available in ANSI C
& bitwise AND operator
| bitwise OR operator
^ bitwise XOR operator
~ Bitwise Complement(NOT) operator
>> Bitwise left shift operator
<< Bitwise right shift operator
above is the example of Bitwise Operators in ANSI C Programming, in this example we use Bitwise left shift operator The left shift operator shifts the bits of the left operand to the left by a specified number of positions. Zeros are filled in on the right. Here we shift 4 bit left side so our actual value is 34(0010 0010) and after left shift operator value is 544(0010 0010 0000) in second example of Bitwise Complement (NOT) operator.
B&R Automation Studio Increment and Decrement Operators in ANSI C Programming
increment and decrement operators in ANSI C are used to add or subtract value of a variable by 1. these operator perform operation on numerical or real values. Following are Increment and Decrement operator
++ Increment operator
-- Decrement operator
above is the example of B&R Automation Studio Increment and Decrement Operators in ANSI C Programming, value_1 increment by 1 up to max value. and decrement operator decrement value_2 by one up to minimum rang of data type.
B&R Automation Studio Assignment operators in ANSI C Programming
Assignment operators are use to assign values on variable or tag. They combine the assignment operation with another operation, such as arithmetic or bitwise, into a single statement. following are the Assignment operators in ANSI C Programming
= Simple assignment operator
+= Addition assignment operator
-= Subtraction assignment operator
*= Multiplication assignment operator
/= Division assignment operator
%=Modulus assignment operator
&= Bitwise AND assignment operator
|= Bitwise OR assignment operator
^= Bitwise XOR assignment operator
>>= Bitwise Left shift assignment operator
<<= Right shift assignment operator
~= Complement(NOT) assignment operator
above is the example of B&R Automation Studio Assignment operators in ANSI C Programming in this example we use simple assignment operator and addition assignment operator. our main value is same in a first line of program 15 assign to value_1.The addition assignment operator adds the value on the right-hand side to the variable on the left-hand side and assigns the result to the variable on the left-hand side. so the value_2, value is added by 15 at every scan cycle up to reach max integer.