I have been trying to convert -9811 to two's complement. I am getting the wrong answer for some reason, and I am not sure why.
$$ 9811 \div 2 \to R1 $$ $$ 4905 \div 2 \to R1 $$ $$ 2452 \div 2 \to R0 $$ $$ 1226 \div 2 \to R0 $$ $$ 613 \div 2 \to R1 $$ $$ 306 \div 2 \to R0 $$ $$ 153 \div 2\to R1 $$ $$ 76 \div 2 \to R0 $$ $$ 38 \div 2 \to R0 $$ $$ 19 \div 2 \to R1 $$ $$ 9 \div 2 \to R1 $$ $$ 4 \div 2 \to R0 $$ $$ 2 \div 2 \to R0 $$ $$ Creates\ unsigned\ binary\ number.. $$ $$ 0011001010011 $$ $$ When\ inverted\ becomes\ 1100110101100 $$ $$ 1100110101100 + 1 = 1100110101101 $$
However, the correct answer is $101100110101101$. For some reason it has 15 bits instead of 13.
What did I do wrong?
The first problem is that you didn’t complete the conversion of $9811$ to binary: after that last division you have a quotient of $1$, which will be your final remainder, so that
$$9811_{\text{ten}}=10011001010011_{\text{two}}\,.\tag{1}$$
The second is that two’s complements have to be taken with respect to a specified power of $2$ — equivalently, to a specified number of bits. It appears that you were supposed to take the two’s complement relative to $2^{16}$, to get a $15$-bit result. Thus, you need to expand the $14$-bit number in $(1)$ to $010011001010011$, complement that to get $101100110101100$, and add $1$ to get $101100110101101$.