Home > Uncategorized > Signed-magnitude: The integer representation of choice for IoT?

## Signed-magnitude: The integer representation of choice for IoT?

What is the best representation to use for integer values in a binary computer? I’m guessing that most people think two’s complement is the answer, because this is the representation that all the computers they know about use (the Univac 1100/2200 series uses one’s complement; I don’t know of any systems currently in use that make use of signed magnitude, pointers welcome).

The C Standard allows implementations to support two’s complement, one’s complement and signed magnitude (the Univac 1100/2200 series has a C compiler). Is it time for the C Standard to drop support for one’s complement and signed magnitude?.

Why did two’s complement ‘win’ the integer representation battle and what are the chances that hardware vendors are likely to want to use a different representation in the future?

The advantage of two’s complement over the other representations is that the same hardware circuits can be used to perform arithmetic on unsigned and signed integer values. Not a big issue these days, but a major selling point back when chip real-estate was limited.

I can think of one market where signed magnitude is the ‘best representation’, extremely low power devices, such as those that extract power from the radio waves permeating the environment, or from the vibrations people generate as they move around.

Most of the power consumed by digital devices occurs when a bit flips from zero to one, or from one to zero. An application that spends most of its time processing signals that vary around zero (i.e., can have positive and negative values) will experience many bit flips, using a two’s complement representation, when the value changes from positive to negative, or vice-versa, e.g., from 0000000000000001 to 0000000000000000 to 1111111111111111; in signed magnitude a change of sign generates one extra bit-flip, e.g., 0000000000000001 to 0000000000000000 to 1000000000000001.

Simulations show around 30% few transitions for signed magnitude compared with two’s complement, for certain kinds of problems.

Signed magnitude would appear to be the integer representation of choice for some Internet-of-Things solutions.

Tags:
1. August 7th, 2017 at 01:08 | #1

IMO this would be a useful simplification and tidy up an old wart. All C/C++ code written today that deals with the “unspecified bits” such as byte packing is tested with two’s complement. There isn’t any hardware to test the other formats. Any code compiled for a different numeric type would need thorough validation. So remove the old ambiguity. It isn’t the best technique today anyway.

If one’s complement or signed-magnitude were introduced today, it should be given its own type intrinsics, completely separate from [u]int{8,16,32,64}_t. Raw intrinsic types or typedefs would be used where the format was important, there would be type promotion to *int*_t as ints promote to floats, and compilers could add flags to allow “legacy” interpretation of int as non-two’s-complement.

1. No trackbacks yet.

A question to answer *