# Welcome to CS

With slight modifications can use our normal algorithms for doing binary math. Take addition for example. We are familiar with adding base ten numbers column by column, carrying to the next column any time we get a value of 10 or more in the present column. In base two, each column can only store a 0 or a 1. So any value over 1 means we have to carry. 2 ($${10}_2$$) means “zero in this column, carry a 1”, 3 ($${11}_2$$) means “one in this column, carry 1 to the next column.”
Below is shown the process of adding 15 ($${1111}_2$$) to 6 ($${0110}_2$$).
Animation used by permission of Virginia Tech

### Subsection4.4.1Overflow

One thing we do have to watch out for any time we have a fixed number of bits to represent numbers is overflow. That is when a value becomes too large to store in the bits we have. When we are doing math on paper, we can add as many digits as we need. But when an electric circuit is doing math, there is a fixed number of digits that can be represented. For example, say we are using 4-bit numbers and we try to add 9 + 9 ($${1001}_2$$ + $${1001}_2$$) - any bits past 4 need to be discarded.
1  1    (Carries)
1001   (9)
+1001   (9)
10010   (18)
Keep only the last 4 bits:
0010   (2 !?!)

9 + 9 gave us just 2 because we can not store the bit that should represent 16. This is an overflow error. Circuits in computers have to detect when there is a carry-out of the last digit so it can signal an error and software developers have to be careful to watch for these errors. Computers use many more than 4 bits to store each number, but any fixed representation will have limits to how big a value can be stored.
Real software can have bugs when the developers do not use enough bits to represent numbers. Youtube engineers had to add more bits to the storage
1
https://www.wired.com/2014/12/gangnam-style-youtube-math/
for view counts of the video Gangnam Style when the view counter for the video was threatening to overflow the 32 bits they had originally used.
You can also see an overflow bug at work in the game Hearthstone.
2
http://www.codeproject.com/Articles/802368/Integer-Overflow-in-Hearthstone
.

### Checkpoint4.4.2.

What is binary 1011 + 0001?
• 1102
• There are no 2’s in binary!
• 1010
• Forget to carry?
• 1000
• Forget to carry?
• 1100

### Checkpoint4.4.3.

What is binary 0110 + 0101?
• 1011
• 0111
• 1111
• 1001
You have attempted of activities on this page.