Picking up this specific bit:
When you add 2's complement numbers, does it just always mean you have to work in a predefined number of bits, and if so, why?
Yes, you need to know the number of bits you are going to be working with, because that determines what the two's-complement representation of your negative number will look like.
So, in your example, you have:
+27 0001 1011b
+ -17 1110 1111b
-------------------
+10 0000 1010b
where there would be a "carry" out of the 8th-bit. If we were to incorrectly do the same calculation using more bits, and taking note of the 8th-bit carry, we would get the wrong answer:
+27 0000 0001 1011b
+ -17 0000 1110 1111b << WRONG representation of "-17" in 12 bits.
------------------------
+266 0001 0000 1010b << WRONG answer in 12 bits.
However, if we do this again, but using the correct 12-bit representation of -17
, then we again get the correct result, although here we are "ignoring" the carry out of the 12th bit:
+27 0000 0001 1011b
+ -17 1111 1110 1111b << Correct representation of "-17" in 12 bits.
------------------------
+ 10 0000 0000 1010b << Correct answer in 12 bits.
Conceptually, you can think of the "true" two's-complement representation of -17
as being an infinite string of 1
s, ending in ...10 1111
. When doing calculations with a finite number of bits, you take just enough of those 1
s to fill your register and discard any "carry" that would go outside that size.