How Computers Do Math

Zaid Humayun
The Startup
Published in
13 min readNov 16, 2018

--

To understand the latter half of this article, you will need to know Boolean Algebra. This is not a topic I discuss in this article. Here is a link to where you can learn about it.

Image Source: https://www.computerscience.gcse.guru/theory/logic-circuits

Introduction

I’ve been reading Code by Charles Petzold over the past couple of weeks. That book is an absolute goldmine of information.

I’ve been curious to understand how math operations work inside of a computer on a fundamental level. I’ve always been aware that computers carry out mathematical operations differently from human beings because computers operate in binary.

This book answered a lot of questions I’ve had on this topic, and I want to share that information with you.

I’ll be going over how we can do addition and subtraction using logical operators in code. You can replace these logical operators with their logic gate equivalents in the physical world.

This article is an exercise in curiosity, and nothing more. Have fun with it!

Why Binary

First, let’s start with a simple question. Why do we count the way we do? Why do we count 1,2,3,4,5,6,7,8,9,10? Any numbers that come after that are the same with an additional or different digit placed to the left?

--

--