My online assembly class doesn't really show us how to find the additive inverse of finding the additive inverse of binary, and I can't find much online. The question is: find the additive inverse of 0000 0000 1110 1111 1010 1101 0110 1100. Any insight on how to solve this or some steps would be great. Thanks.
[Math] Find the additive inverse of binary number
binaryinverse
Related Solutions
Let $0\leq x,y\leq2^{N}-1$, s.t. $x<y$.
To show that I get the "correct result", means to show that: $(x-y)\mod2^N = 2^N-(y-x)$
Now if I apply $\mod 2^N$ on RHS:
$(2^N-(y-x))\mod 2^N$
$(2^N+(x-y))\mod 2^N=$
$(2^N\mod 2^N+(x-y)\mod 2^N)\mod 2^N= $
$(0 + (x-y)\mod 2^N)\mod 2^N=$
$(x-y)\mod 2^N$
You cannot expect to use integer binary addition on two floating-point representations and get a meaningful result.
First, $1.111$ cannot be represented exactly in binary floating point. Your 00111111100011100011010100111111
is actually the IEEE-754 single precision representation of the number
$$ 1.11099994182586669921875 $$
which is the closest representable number to $1.111$. This breaks up as
0 01111111 00011100011010100111111
sign biased exponent fractional part of mantissa
and stands for the number $$ 1.00011100011010100111111_2 \times 2^{127-127} $$
The representation of $2.222$ is twice that, with the same mantissa but the exponent one higher. When we add them we must position the mantissas correctly with respect to each other:
1.00011100011010100111111
+ 10.0011100011010100111111
----------------------------
= 11.01010101001111110111101
11.0101010100111111011110 <-- rounded to 1+23 bits mantissa using round-to-even
0 10000000 10101010100111111011110
sign biased exp fractional mantissa
And the representation 01000000010101010100111111011110
corresponds to the number
$$ 3.332999706268310546875 $$
Note that this is not the closest representable number to $3.333$, which would be the next one,
$$ 3.33329999446868896484375 $$
but the round-to-even rule led to rounding down the full result of the addition, which compounded the error inherent in the two inputs each being slightly smaller than $1.111$ and $2.222$.
Best Answer
If we're dealing with $n$-bit binary numbers, i.e., only numbers in the range $0$--$2^n - 1$, and for a given $a$ we denote by $\bar a$ that $2^n$ bit number whose every bit is the opposite to that in the same position in $a$, then
$a + \bar a = \underset{\text{n bits}}{1 1 \ldots 1}; \tag 1$
then
$a + \bar a + 1 = \underset{\text{n bits}}{0 0 \ldots 0}; \tag 2$
thus
$-a \equiv \bar a + 1; \tag 3$
for example, with
$a = 1110, \tag 4$
we have
$\bar a = 0001, \tag 5$
$-a = \bar a + 1 = 0010; \tag 6$
it is easy to check that
$-a + a = a + \bar a + 1 = 1110 + 0010 = 0000; \tag 7$
again, with
$a = 1010, \tag 8$
$\bar a = 0101, \tag 9$
$-a = 1 + \bar a = 0110, \tag{10}$
and we see that
$1010 + 0110 = 0000. \tag{11}$
The reader may easily try this out/check it for larger values of $n$ than $4$.
It is important to remember that we are really dealing with arithmetic $\mod 2^n$, i.e., in $\Bbb Z_{2^n}$, where the elements are written in binary representation.