Logic

Basic Understanding of Logic

  • Logic, in computer science, is concerned with how we make decisions based on multiple conditions.
  • Processes in a computer, like calculations and data processing, are performed in a logical sequence.
  • Understanding the basics of logic is crucial to writing well-structured code.

Boolean Logic

  • Boolean Logic only has two possible values: true or false.
  • It’s named after mathematician George Boole, who set the groundwork for modern digital computer logic.
  • In programming, Boolean logic corresponds to the yes/no or on/off principle.

Logic Gates

  • Logic Gates are used to implement Boolean logic in hardware.
  • The basic types are: AND, OR and NOT.
  • ‘AND’ output true when both inputs are true.
  • ‘OR’ output true when at least one input is true.
  • ‘NOT’ output the opposite of the input.

Other Logic Gates

  • There are also combined gates such as: NOR, NAND, XOR and XNOR.
  • ‘NOR’ is the opposite of the OR gate - it outputs true only when both inputs are false.
  • ‘NAND’ is the opposite of the AND gate - it outputs true unless both inputs are true.
  • ‘XOR’ or exclusive OR only outputs true when the inputs are different.
  • ‘XNOR’ or exclusive NOR only outputs true when the inputs are the same.

Truth Tables

  • A Truth Table is a mathematical table used in logic to calculate the results of a logic function for each possible combination of input values.
  • Understanding truth tables is vital for understanding how logic gates work.

Binary Logic

  • Binary Logic deals with variables that take on just two values: 0 and 1, which also correspond to logic values false and true respectively.
  • Binary logic is the heart of digital electronics and computer science.

Logical Operators

  • Logical Operators are used to manipulate true or false values.
  • Common ones are: AND, OR, NOT, NAND, NOR, XOR, and XNOR.
  • These are used to specify multiple conditions within a sequence of code.