<!DOCTYPE html>Love Bit(e)s

Love Bit(e)s

Love Bit(e)s

Currently Reading: The Manga Guide to Microprocessors, The Manga Guide to Electricity, The Little Schemer

In my previous post, Black Magic Computers, I talked about semiconductors, transistors, logic gates, and more. This will hopefully build upon that post, as I talk about binary arithmetic.

So, what is a bit?

The dictionary definition of a bit is “a small piece, part, or quantity of something”, but we also have heard bit in computing a lot. A bit is short for binary digit and is the smallest unit of data that a computer uses. It has a value of either a 0 or a 1.

I like to think of them as the computer world’s version of atoms.

A bit represents either high voltage* (on), which is a 1, or low voltage (off) which is a 0.

*Voltage is the measurement of volts. Volts are the difference from high to low potential. Check out this Khan Academy video for more information:

(Ignoring Hexadecimal for now)

Normally, we use the decimal number system (base 10 notation), but you can do calculations with binary (base two notation) digits as well!

If we have a decimal number, such as 205, it could also be expressed as two one hundreds, zero tens, and five ones. The key words being the “places” we use, ones, tens, hundreds, etc. This is what makes it base ten notation.

If we make those smaller and bring it down to base two, having our places be ones, twos, fours, ands eights, we would be using base two notation.

In binary we can use this to express digits like such:

Place:   8  4  2  1 
Binary: 1 0 1 1 => 11

In this example we are counting all the places of the ones, or 8 + 2 + 1, which equals 11!

Binary Addition

First, starting off adding two bits we get a table that looks like this:

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

The last one is the most important to look at, which is 1 + 1 = 1 0. The 1 in the 1 0 is carried over from the previous place.

Trying out four bit addition, we could do something such as :

0 1 1 1 => 7 
+ 0 0 1 0 => 2
1 1
1 0 0 1 => 9

Binary Subtraction

Binary uses a technique called Two’s Complement to create negative values. To get Two’s complement of an integer you can write out the binary, invert the digits, and then add one.

If we wanted negative seven:

0 1 1 1 = 7
1 0 0 0 = the inversion of 7
+ 1
1 0 0 1 => -7 / 9

You may be saying “but that is nine!”, and you’d be right. But, let’s put this in an equation.

0 1 1 1 = 7
+ ( 1 0 0 1 ) = -7
0 0 0 0

The signature of the integer is dependent on where it is at in the equation. Here we can see it is negative seven since it is on the bottom, and if the equation were flipped, it would be a nine. Typically, the larger number resides on top, which is how we can find the signature of the integer by learning the top integer.

The last important thing to be covered is overflow. When doing four bit, two bit, or any digit math, your answer should be the amount of digits of the math type you’re doing. Above we are doing four bit addition, even though there is a carry in that problem, and the full answer is 1 0 0 0 0, we ignore that 1 since it flows past four digits.

My current goals are to figure out the best way to learn Python for me, I’ve been trying a mixture of Codewars and reading, but none of it really sticks. I’ve been told repetitively that someday it “clicks” though. If you have any good videos or reading recommendations, send them my way!