Comments by "Lawrence D’Oliveiro" (@lawrencedoliveiro9104) on "Scott Manley"
channel.
-
4
-
4
-
There are 3 well-known ways of representing signed integers using binary notation: sign-magnitude, ones-complement, and twos-complement.
Sign-magnitude is probably the first one that anybody would think of: reserve one bit for the sign, and use the rest of the bits to represent the magnitude.
Let’s say we have 5-bit integers, for simplicity. After reserving one bit for the sign, we have 4 bits left for the magnitude. If we put the sign bit at the left and use 0 for positive and 1 for negative, then +3 could be represented as
00011
while -3 would be
10011
Addition and subtraction requires complicated logic to extract the sign and magnitude, and do different things with the magnitudes depending on whether the signs are same or different, then deciding what sign to attach to the result.
In ones-complement, +3 is represented the same as before, but instead of negating by flipping only the sign bit, we flip all the bits. So -3 becomes
11100
Note that complementing applies to zero as well. Thus, both
00000
and
11111
represent zero. The latter can be considered to be “negative zero”, since its sign bit is 1. When we add +3 and -3:
00011
+11100
=11111
which is indeed one of the representations of zero.
Twos-complement gets rid of the redundant representation of zero, by redefining negation to be done by flipping all the bits, then adding 1. Thus, -3 is now represented as
11101
So adding +3 and -3:
00011
+11101
=100000
And throwing away the 1 that has gone into the 6th bit (because we can only represent 5 bits) gives zero, as expected.
4
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
Science is about confronting the tough questions, not shying away from them.
If the Earth is flat, are the other planets flat, too? If so, why do they look round?* If not, why is the Earth special?
Remember, Galileo was the first human to see other planets (apart from the Moon) as round disks through his telescope, as opposed to dots* with the naked eye.
** Though I think Venus, when it gets close enough to us, gives a hint of being something more than a dot, in its crescent phases.
2
-
2
-
2
-
2
-
2