Doubt with signaled binary sum

Asked

Viewed 606 times

5

I’m studying operations with binary numbers flagged and I came up with a question I’d like you to clarify:

by adding two numbers with 6 bits being 001111(+15) and 010110(+22) I got the result 100101(-5) and the correct would be 0100101(+37).

What I want to know is whether this addition of 0 in front is considered overflow (since it bursts 6 bits) or has no importance?

  • 2

    100101 is 37 not considering the first bit as a signal. What negative format are you considering ? 2 ?

  • @Isac, to get -5, must be an unusual addition to Ulas. It should be simply disregard the signal bit, the rest giving the number module

  • 1

    @Jeffersonquesado Yeah, it’s because there are some different representations of binary, so you need to know how he was considering it. The most common is even complement of 2 as you gave in the reply, but I doubt that is what the AP is considering

  • @Isac, I know complement of 2, complement of 1 (which allows the existence of -0) and that of the signal magnitude. I think I could augment my response with these numbering schemes. You’re right as to need to consider what scheme is being used. But the truth is, I’m too lazy to add to the answer right now, so if you can put an answer to those quirks, that would be great

  • @naosei, do you think there is still something left that I can handle in the reply? I saw that you liked her, I wondered if I could leave even more complete

  • 1

    @Jeffersonquesado is great, clarified my doubt, thank you

Show 1 more comment

1 answer

10


In fact, the result obtained is the right one (assuming complement of 2 , as perceived by @Isac). But it’s not -5, and yes -27. But if you assume magnitude sign (see below), the binary you got would be -5 same, but I believe that one does not sum up this way in the sign magnitude representation, so I am led to believe that you are using complement 2.

We are in a 6-bit world. This world can represent up to a maximum of 64 distinct numbers. If there was no sign, these numbers would vary from 0 to 63. As there is a sign, in the complement of 2 the numbers represented are 0 to 31, -32 to -1.

If you were in a world of variable habitation, then there would be the presence of an extra bit just to indicate that it is not a negative number, but it is not the case.

Adding two positives and getting a negative in my memory is not a overflow. Overflow would add up in such a way that it would take 7 signal-independent bits to represent the sum obtained. That is, it would be the sixty-fifth number, bursting the capacity of the 6 bit representation. This occurs with -1 + 1.

Some extreme and interesting numbers with 6 bits:

0   : 000 000
1   : 000 001
31  : 011 111
-32 : 100 000
-1  : 111 111

Some operations:

1 + -1 = 0
  000 001 +
  111 111 
  -------
  000 000 (1 de overflow)


15 + 22 = -27
  001 111 +
  010 110
  -------
  100 101

31 + -32 = -1
  011 111 +
  100 000
  -------
  111 111

Binary notations with signal

There are 5 main notations for binary numbers with signal:

  1. Use an explicit sign, as in the decimal base; but this implies that it is not possible to represent binary numbers with only two symbols of the numerical alphabet (base 10 uses 11 symbols to represent positive and negative integers, 12 to count the decimal separator and broken numbers)
  2. Complement of 2, most commonly used mode for being extremely simple arithmetic for the processor/ULA
  3. Complement of 1, only known for academic purposes
  4. Signal magnitude, where the signal bit is totally independent of the magnitude bits
  5. "Offset value", where it is initially considered that the number has no sign and then subtracts by a "offset", used to calculate the exponent of floating points

    did not find a better name; reading the wikipedia article found the term bias as what I called "displacement", but did not understand what would be the official name of the numerical representation scheme

Explicit sign

Not very usual for processors. Much more common to represent negative numbers on other bases, or with numbers without fixed housing:

101    : +5 em decimal
-101   : -5 em decimal
-10001 : -17 em decimal
10001  : +17 em decimal

As a negative side, it requires the existence of a third symbol, which makes it unattractive for computers working with binary digits. Not to mention that even with trinary digits it would be a huge waste of space...

Complement of 2

It is the most used scheme by Ulas in the world due to its simplicity of handling. There is no difference between adding a negative number on this basis with a positive one. Or vice versa. Or two positives. Or two negatives. The sum logic is identical, it does not need any complementary circuit or differentiated sum algorithm when considering negative numbers.

Behold this reply from @ramaral teaching to calculate the complement of 2

This scheme was designed in such a way that the sum of a number and its negative is always a string of zeros (with a overflow resulting from the transaction).

Due to its inherent characteristics, there is a negative number more than positive. But this negative number added to itself results in zero. For n bits, the largest negative number in terms of magnitude is -2^(n-1), so in 6 bits is -32, in 8 bits is -128.

Complement of 1

This numerical scheme was elaborated as the simple negation of the positive number. A simple bit-to-bit negation of number generates its complement of 1. This implies the existence of +0 and -0. This also implies that the amount of positive and negative numbers are identical. So, for n bits, the largest negative number in terms of magnitude is -2^(n-1) +1, so in 6 bits is -31, in 8 bits is -127.

Behold this reply from @ramaral teaching to calculate the complement of 1

I personally know of no practical use for representing numbers like this.

Signal magnitude

The idea of this scheme is very simple, even used (roughly) in floating numbers: the first bit indicates signal, the other bits are the magnitude of the number. This implies the same remarks I put up for complement 1:

  • existence of +0 != -0
  • same amount of positive and negative numbers
  • same limits for positive and negative numbers

In addition to this idea being used for floating numbers, and perhaps used to represent larger numerical abstractions (like suddenly some implementation of BigInteger Java use a signal bit), I don’t know many utilities of this representation.

"Misplaced value"

This number representation scheme is very simple. Imagine that I start from -15. All I report later is how far it is from this base offset value. The number I report is a positive integer.

Another way of seeing it is: the number given has no signal, but after reading it, I move it -15.

Imagine I have the following five-bit number:

11010

If I were to read this number as a conventional no-signal number, I would be worth 2+8+16=26. However, it is actually displaced 15 houses, so the value I must consider is 26-15=11.

Already for that amount:

00101

That would be worth 5 reading as if it were a conventional number, read as 5-15=-10.

This "offset value" notation is used to calculate which exponent is used in the floating point format IEEE 754. This displacement of -15 is used by the format of IEEE half precision, officially known in IEEE 754-2008 jargon as binary16.


Additional reading:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.