Answer the question
In order to leave comments, you need to log in
Subtraction in direct code?
Hello! Faced a problem.
There is a number 4 -> 0100 (in direct code)
There is a number 7 -> 0111 (in direct code)
When I try to get the difference 4 - 7, I get 0X11 as a result, where X is some value that I cannot get , because I cannot "take" 1 from the next category. How to solve this problem?
Answer the question
In order to leave comments, you need to log in
It is better to subtract in the reverse code, through addition. Or subtract the smaller from the larger.
But if you so desire, you can subtract until the digits run out.
00000100
-
00000111
=
*1111101
But here's the problem, the last digit (where I have *) should actually be -1. there is simply no other place to borrow from.
If we do this borrowing, we get X=11111101 and -1 in the next, non-existent bit.
This is actually already a number in the reverse code! If we take a bit NOT and add 1, then we get 0011 = 3, as we should have. After all, the number itself is -3.
But why is it so? Your number is actually X - 2^8 (because the 1 is in the next non-existent digit).
Or - (2^8-X). Bitwise NOT. it's just a subtraction from 111...111. Those. ~X=(2^8-1) -X.
Ostuda 2^8-X = ~X+1.
Those. your number is actually ~X+1 modulo.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question