Binary addition, overflow and shifts

Robusta Study

Revision videos, vocabulary practice and written questions for IGCSE.

Binary addition, overflow and shifts

Adding binary numbers with carries, overflow when a ninth bit is needed, and logical shifts as multiply and divide.

Transcript

To add binary numbers, work from the right, just like in denary. Zero plus zero is zero. Zero plus one is one. One plus one is zero, carry one. And one plus one plus one is one, carry one.

Let's add zero one one zero one one zero one, which is one hundred and nine, and zero zero one one zero one one one, which is fifty five.

Add column by column from the right, and write each carry above the next column. The answer is one zero one zero zero one zero zero, which is one hundred and sixty four.

A register holds a fixed number of bits, here eight. If a sum needs a ninth bit, there is nowhere to store it. This is called overflow.

Add two hundred and one hundred. The true answer, three hundred, needs nine bits. The extra carry is lost, leaving only forty four, which is wrong.

So the largest number that eight bits can hold is two hundred and fifty five. Anything bigger causes an overflow error.

A logical shift moves every bit left or right. Empty places are filled with zeros, and bits pushed off the end are lost.

Shifting left by one place multiplies by two. Thirteen becomes twenty six. Shifting left by three places multiplies by eight, giving one hundred and four.

Shifting right by one place divides by two. Thirteen becomes six, because the bit that falls off the end is lost, so the answer is rounded down.

Carry the ones, watch for overflow, and remember: shift left to multiply, shift right to divide.

More in this series