Boolean datatype
What is boolean datatype?
Data type that has one of two possible values, usually denoted as true and false. Which is intended to represent the two truth values of logic and Boolean algebra.
It is named after George Boole1, who first defined an algebraic system of logic in the mid 19th century.
Conditional statements, which allow different actions by changing control flow depending on whether a programmer-specified Boolean condition evaluates to true or false.
Boolean datatype primary associated with conditional statements, which implement different actions behavior with control flow.
If there is no explicit Boolean datatype (like in C90), can boolean datatype be represented?
Yes usually used int to represent true (0) and false (1) values.
The implementation of Booleans in computers are most likely represented as a full word or a bit?
Usually as full word, this is usually due to the way’s computers transfer blocks of information.
Most programming languages, have support for Boolean algebraic operations such as:
Conjunction (AND, &, *): returns true if both operands are ==true==.
Disjunction (OR, |, +): returns true if at least one operand is ==true==.
Equivalence (EQV, =, ==): returns true if both operands are the same.
OR - returns true when one or both inputs are true, XOR returns true when?
When inputs are different. Exclusive OR (XOR), true only if inputs differ.
print(True ^ False, False ^ True, True ^ True, False ^ False)
print(True or False, False or True, True or True, False or False)Results:
True True False False
True True True False
Negation (NOT, !): Returns the opposite of the operand. NOT true and NOT false will return ==false==.
Boolean expression
Expression which produce a Boolean value when evaluated. Used in many programming languages as built-in type.
In C you need to include stdbool.h to use bool type.
#include <stdbool.h>
printf("true: %d\n", true); // true: 1
printf("false: %d\n", false); // false: 0