E
E
elisey4742016-10-16 17:05:10
IT education
elisey474, 2016-10-16 17:05:10

What is the direct code for the number -128?

At school, we go through the direct, reverse and additional number code.
They gave a definition - the sign bit is placed the number 1, and in the bits of the digital part of the number - the binary code of its absolute value - a direct code.
Well, they said that in a single-byte format, signed numbers can only be written from -128 to 127.
In the example, they gave the number -1. That is, its absolute value is 1 and the direct code is 10000001
And what about the number -128. Its absolute value is 10000000. How to form a direct code if the sign does not fit anymore, because the absolute value has scored everything?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
15432, 2016-10-16
@15432

-128 in one-byte representation looks like
this. This uses the two's complement code. For example, -1 would look like this:
The idea is that when you add such a negative number to exactly the same positive number, the result will be zero. (actually there is a register overflow).
As you can see, -128 has a really negative sign (the most significant bit is one) and when added to 128, you get zero.
If you were asked to "algorithmically" get the two's complement representation of 128, then no "sign" needs to be added. In the process of obtaining an additional code from a direct one, it itself is formed there.
128 = b "1000 000" - direct number entry. It doesn’t fit into a signed one-byte type, as you rightly noted, but okay, let’s continue. Reverse number code - change all 1 to 0 and vice versa. We get b"0111 1111". Additional code - add one. We get b"1000 0000". This will be the representation of the number -128 in two's complement and its representation in a one-byte signed type. (unsigned char in C/C++)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question