Two's complement
Negative numbers in binary: the -128 place value, invert and add one, and reading a signed byte.
Transcript
So far our binary numbers have only been positive. To store negative numbers, computers use two's complement.
In an eight bit number, the left most bit is now worth minus one hundred and twenty eight, instead of plus. The other place values stay the same.
So zero one one one one one one one is one hundred and twenty seven, the biggest number. And one zero zero zero zero zero zero zero is minus one hundred and twenty eight, the smallest.
To make a negative number, start with the positive. For minus twenty five, begin with twenty five: zero zero zero one one zero zero one.
Step one: flip every bit. Step two: add one. The answer is one one one, zero zero one one one.
Check it with the place values. Minus one twenty eight, plus sixty four, thirty two, four, two and one, makes minus twenty five.
To read a negative number, just add up the place values. One one one one zero one zero zero is minus one twenty eight, plus sixty four, thirty two, sixteen and four. That is minus twelve.
The great thing about two's complement is that addition just works. Twenty five plus minus twenty five is zero, once the extra carry is thrown away.
The left most bit is minus one twenty eight. Flip the bits, add one, and you have the negative.
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:30Binary addition, overflow and shifts
Adding binary numbers with carries, overflow when a ninth bit is needed, and logical shifts as multiply and divide.
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.