ForHosting KIT · Developer Utilities

Signed magnitude representation calculator

This signed magnitude representation calculator converts a signed decimal integer into a fixed-width binary pattern and converts that pattern back into a number.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

Unlike two’s complement, sign magnitude reserves the most significant bit exclusively for the sign and uses every remaining bit for the absolute value. Choose an operation, provide the value and total bit width, and receive the sign bit, magnitude bits, numeric magnitude, complete pattern, and decoded value. The result also identifies the special negative-zero representation that this number system permits.

How to encode a signed integer

Select encode, enter a base-10 integer in the value field, and choose a total width from 2 through 53 bits. The calculator first separates the sign from the absolute magnitude. A negative input produces a leading sign bit of 1, while zero and positive inputs produce a leading sign bit of 0. It then converts the magnitude to binary and pads that binary value on the left until it occupies exactly one fewer bit than the selected width. The sign bit and padded magnitude are joined to form the final pattern. For example, the magnitude 37 is 0100101 in seven bits, so negative 37 at eight bits becomes 10100101. Sign magnitude cannot use the sign position to increase the positive or negative range. At width w, the largest permitted magnitude is 2 raised to w minus 1, minus 1. Inputs outside that symmetric range are rejected rather than truncated, wrapped, or silently changed, which makes the result safe to use in coursework, documentation, and test vectors.

How to decode a binary pattern

Select decode and enter a binary value containing exactly as many digits as the chosen bit width. Leading zeros matter, so the pattern is accepted as text instead of as a decimal number. The first digit is interpreted only as the sign: 0 means nonnegative and 1 means negative. The remaining digits are parsed as an unsigned binary magnitude. If that magnitude is nonzero, the sign is applied to obtain the decoded decimal integer. The output keeps the original pattern and also separates sign_bit, magnitude_bits, and magnitude so each stage can be checked independently. A pattern such as 10100101 therefore has sign bit 1, magnitude bits 0100101, magnitude 37, and decimal value -37. The calculator requires the declared width and actual pattern length to agree. It rejects spaces, prefixes such as 0b, separators, and digits other than 0 or 1, preventing an apparently valid answer from being produced from an ambiguous bit sequence.

Understand range and negative zero

Sign magnitude is easy to read because the sign is stored separately, but this layout has consequences that differ from two’s complement. The available numeric range is symmetric: an eight-bit pattern represents ordinary values from -127 through 127, not -128 through 127. It also has two encodings for numerical zero. All zero bits represent positive zero, while a sign bit of 1 followed entirely by zero magnitude bits represents negative zero. Both decode to the numeric value 0, so the negative_zero field explicitly records which representation was supplied. That distinction is useful when examining historical computer formats, floating-point sign concepts, teaching examples, or hardware exercises where the bit pattern itself matters. The calculator never converts between sign magnitude and two’s complement implicitly. If a source system uses another signed representation, identify it before interpreting its bits. For reliable comparisons, keep the same bit width throughout a set of calculations, because padding changes the complete pattern even though it does not change the magnitude or decoded integer.

Check digital logic exercises

Verify sign bits, magnitude padding, representable ranges, and decoded answers at a specified width.

Create deterministic test vectors

Generate exact sign-magnitude patterns and structured intermediate values for encoder or decoder tests.

Inspect legacy numeric formats

Interpret stored bit patterns while preserving the meaningful distinction between positive and negative zero.

What does an API calculation cost?

Each API request costs $0.002. The same deterministic calculation is also available free in your browser.

What bit widths are supported?

You can choose any total width from 2 through 53 bits, including the sign bit.

Why is the range smaller than two’s complement?

One bit stores only the sign, and the remaining bits store magnitude, so an eight-bit value has a maximum magnitude of 127.

How is negative zero handled?

A pattern with sign bit 1 and an all-zero magnitude decodes numerically to 0 and returns negative_zero as true.

Can I include a 0b prefix or spaces?

No. A decoding value must contain exactly the requested number of binary digits with no prefix, spaces, or separators.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/elec/signed-magnitude

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/elec/signed-magnitude \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"operation":"encode","value":"-37","bit_width":8}'
{
  "operation": "encode",
  "value": "-37",
  "bit_width": 8
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "elec.signed_magnitude",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →