# How Computers Calculate

Computers can do many things nowadays, from playing Jeopardy to driving cars, but they ultimately just do a few simple operations on binary numbers:

1. Get some bits of information (from storage), like `0010` and `0101` along with an operation to perform on them, like addition.
2. Perform the operation and store it for short-term or long-term use.

Computers are able to perform these operation with simple logic gates that are similar to the physical switches and relays used in the earliest computers.

A Logic gate works by producing a specific binary output for a given input. All input and output is just `1`'s and `0`'s. For example, the "AND" gate only outputs `1` if both its inputs are `1`'s. This can physically be created by putting 2 switches in a row:

Other input wires or electromagnets control the 2 switches. Only when both switches are closed (an input of `1`) will the above gate output `1`. (See simple animations of logic gates here.)

Logic gates are combined together to produce calculating devices and are the fundamental physical logic of a computer. You could even build your own calculator by combining together enough logic gates.

CPU
The CPU is "in charge" of the actual computation a computer does, and it uses an Arithmetic unit built with logic gates to perform the actual operations. It also has a control unit which manages the flow of bits around the CPU. Below is an animation from Virginia Tech of the CPU at work getting data and adding it together.