Boolean operators AND, OR, and NOT are used to manipulate logical statements. Boolean operators are the core operators used in digital control systems as well as computer systems. AND and OR are binary operators, while NOT is a unary operator. Let A and B be two logical statements or variables representing logical statements. If a logical statement is true it may be assigned the value 1, and if a logical statement is false it may be assigned the value 0. Table gives details of the three operators AND, OR, and NOT.
Complex Boolean expressions are often resolved with the help of truth tables. A truth table displays the conditions in which the expression will be true and when it will become false for all values of variables (either 0 or 1, i.e., 0 for false and 1 for true). For example, let us consider two logic statements A and B. If A is true, it has the value 1, and if it is false its value is 0. These values are substituted in the expression. If the expression evaluates to 1 the expression is said to be true, otherwise it is considered to be false. Table shows the truth table for !A, !B, A I I B, and A&&B.
Illustrates the application of Boolean operators.
#include <stdio.h>
main()
{
int A = 1, B = 0, C =1, S, X, Y, Z, H, F = 1;
clrscr();
S = A || B;
H =!B;
X= A &&!B ;
Y =!(A+B + A*B);
Z= (!A || !B && !C || F);
printf("S = %d\t H = %d\n" ,S, H);
printf("X = %d\t Y = %d\t Z = %d\n", X,Y,Z);
}
Illustrates Boolean operators in if (expression).
#include <stdio.h>
void main()
{
double A= 4.6, B= 0.0, C = -4.2, S, X, Y, Z, H, F =-7.5;
S = A || B;
H =A && F;
X= A && !B ;
Y =!(A+B + !A*B);
Z= (!A || !B && !C || F);
printf("S = %lf\t H = %lf\n" ,S, H);
printf("X = %lf\t Y = %lf\t Z = %lf\n", X,Y,Z);
if (!A || !B && !C || F)
printf("The logic expression= 1.\n");
if (A+B + !A*B)
printf( "The logic expression= 1.\n");
}
Dinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.
Related Articles
Basic Courses
Advance Courses