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
2:41Denary, binary and hexadecimal
Place values, converting denary to binary and back, and why hex is used for bytes.
2:12Two's complement
Negative numbers in binary: the -128 place value, invert and add one, and reading a signed byte.
1:45Text: ASCII and Unicode
Character sets give every character a code. ASCII's 128 codes, Unicode's millions, and the storage trade-off.
1:27Images
Pixels, resolution, colour depth, image file size and metadata.
1:38Sound
Sampling an analogue wave: sample rate, bit depth, quality against file size.
1:50Storage units and file sizes
Bit to pebibyte in steps of 1024, and calculating image and sound file sizes.
1:58Compression
Why files are compressed, lossy against lossless, and run-length encoding step by step.
5:38Unit 1 quiz
Ten questions with a think-time countdown and explained answers.