Boolean is one of the main data types in computer. Boolean logic reflects the binary logic of logic gates and transistors in a computer's CPU.

Part of

Logic gates can be built up into chains of **logical decisions**. Some logic gates may have more than two inputs. The diagram below shows a **complex logic gate** combining three simple gates.

Altogether there are three inputs and eight possible outcomes. To solve the truth table below, first find D, then E and finally Z. Complete a whole columnn before moving on to the next column. D depends only on A, E depends on B and C, and Z depends on E or D.

This logic gate truth table is written as:

A | B | C | D = NOT A | E = B AND C | Z = D OR E |
---|---|---|---|---|---|

0 | 0 | 0 | 1 | 0 | 1 |

0 | 0 | 1 | 1 | 0 | 1 |

0 | 1 | 0 | 1 | 0 | 1 |

0 | 1 | 1 | 1 | 1 | 1 |

1 | 0 | 0 | 0 | 0 | 0 |

1 | 0 | 1 | 0 | 0 | 0 |

1 | 1 | 0 | 0 | 0 | 0 |

1 | 1 | 1 | 0 | 1 | 1 |

This circuit would be written as **Z = D OR E** or **Z = NOT A OR (B AND C)**.

The following example demonstrates how the ALU uses logic gates to perform binary addition. It combines two gates, in parallel. There are two inputs and each gate has a single output - so in total there are two outputs, with four possible outcomes.

The Boolean expressions for this circuit are:

**S = A XOR B**

**C = A AND B**

The truth table for this circuit is:

A | B | S = A XOR B | C = A AND B |
---|---|---|---|

0 | 0 | 0 | 0 |

0 | 1 | 1 | 0 |

1 | 0 | 1 | 0 |

1 | 1 | 0 | 1 |

This gate models a 1-bit binary sum. The possible calculations of a 1-bit binary sum are:

- 0+0=0
- 0+1=1
- 1+0=1
- 1+1=10

S and C together represent the output of the sum of 'A + B'. Each gate can only output a single bit - a number with one place value. 1+1 creates 10 which needs 2 place values, so this is an overflow number. In overflow sums, the result is recorded as 0 and the 1 has to be carried. S represents the recorded 0 and C represents the carried 1.

This configuration is called a binary **half adder**. It is a good way to begin to understand how an ALU is able to perform arithmetic. To perform complete arithmetic that can take account of carry bits and add more than two bits together, two half adders must be combined together to make a **full adder**.

An ALU uses millions or billions of circuits like this cascaded together to perform calculations.

Binary addition and overflow errors is explained further in Numbers and binary addition.