In this class, I learned about the logical operators (e.g. &&, ||, !) and bit operators (&, |, ~, ^).
1. Logical operators
- AND (&&): If A and B are true, it is denoted as 'A && B'
- OR (||): If A or B are true, it is denoted as 'A || B'
- NOT (!): Non-A values output as a result, it is denoted as '!A'
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int A = 1, B = 0, C = 1;
int Result1, Result2, Result3, Result4, Result5, Result6
Result1 = A && B;
Result2 = A && C;
Result3 = A || B;
Result4 = B || C;
Result5 = !A;
Result6 = !B;
print('%d \n', Result1);
print('%d \n', Result2);
print('%d \n', Result3);
print('%d \n', Result4);
print('%d \n', Result5);
print('%d', Result6);
return 0;
}
2. Bit operators
- AND (&): Calculate each bit for AND
- OR (|): Calculate each bit for OR
- NOT (~): Calculate each bit for NOT
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int A = 0b1100, B = 0b1010;
int Result1, Result2, Result3;
Result1 = A & B;
Result2 = A | B;
Result3 = ~A;
printf('%x \n', Result1);
printf('%x \n', Result2);
printf('%x', Result3);
return 0;
}
'Study Meeting > 빡공단 30기' 카테고리의 다른 글
[Day 11] Conditional Statement 1: if and else (0) | 2023.01.11 |
---|---|
[Day 10] Operator 3: Bitwise Shift Operator (0) | 2023.01.11 |
[Day 8] Operator 1: Assignment, Relational, Arithmetic, Incremental Operators in C Language (0) | 2023.01.08 |
[Day 7] Quadratic expression for C Programming (0) | 2023.01.07 |
[Day 6] ASCII Code: How to represent letter in C Language? (1) | 2023.01.07 |