ForHosting KIT · Developer Utilities

Unsigned to signed integer calculator

255 in 8 bits is all ones, so read as a signed number it becomes −1: enter an unsigned value and a width from 2 to 53 bits to get its two's-complement reading, its bit pattern and whether the high bit is set. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Value
255
Bits
8
You get
Signed
-1
Unsigned
255
Binary
11111111
Min
-128

When you cast an unsigned integer to a signed type at the same bit width, modern languages do not change the bits—they reinterpret them under two's complement. A value such as two hundred fifty-five stored in eight bits is all ones; as uint8 that is two hundred fifty-five, but as int8 the high bit is set so the same pattern means negative one. Students, embedded developers, and interview candidates need a fast, deterministic way to see that mapping for any width from two through fifty-three bits without hand-counting residues. This unsigned to signed integer calculator accepts a non-negative value and a bit width, checks that the value fits the unsigned range for that width, and returns the signed two's-complement reading together with the exact bit pattern and a clear high-bit flag. Overflow outside zero through two to the power of the width minus one is rejected instead of silently wrapping.

How unsigned-to-signed two's complement reinterpretation works

Fix a bit width w at least two. Every bit pattern of length w can be read two ways. As an unsigned integer it is a whole number u from zero through two to the power of w minus one.

As a signed two's-complement integer the same pattern is u when the most significant bit is clear, and u minus two to the power of w when that high bit is set. That single rule is why two hundred fifty-five in eight bits becomes negative one, why one hundred twenty-eight becomes negative one hundred twenty-eight (the most negative eight-bit value), and why one hundred twenty-seven stays positive one hundred twenty-seven.

The algorithm never flips individual bits by hand: it compares u against two to the power of w minus one (the half-range threshold), then either returns u unchanged or subtracts the full modulus two to the power of w. Zero always stays zero; the all-ones pattern always becomes negative one at every width. Values must stay inside JavaScript’s safe integer range so every digit remains exact when the result is serialized as a number.

Requests that would not fit the unsigned range for the chosen width—for example two hundred fifty-six in eight bits—are rejected with a clear message listing the allowed maximum, rather than wrapping to zero and hiding a cast bug that students or firmware notes might trust by accident.

Homework and CS organization labs

Check what any unsigned byte or word becomes under a signed cast at 8/16/32-bit widths, including the high-bit midpoint and all-ones cases, against a single shared oracle.

Firmware logs and protocol dumps

Reinterpret unsigned register dumps as signed sensor deltas or offsets at a fixed width when reviewing hex or decimal logs.

What does unsigned to signed mean in two's complement?

At a fixed width w, the same bit pattern is either the unsigned value u in [0, 2^w−1] or the signed value u if the high bit is clear, and u − 2^w if the high bit is set. The bits do not change; only the interpretation does.

Why is 255 equal to −1 in 8 bits?

255 is the all-ones pattern. With the high bit set, two's complement defines the signed reading as 255 − 256 = −1. The same all-ones pattern is −1 at every width.

What range must value fit?

Value must be a non-negative integer in [0, 2^bits − 1]. Signed results then lie in [−2^(bits−1), 2^(bits−1)−1].

Which bit widths are supported?

Widths from 2 through 53 inclusive. Common classroom widths are 8, 16, and 32.

What does the unsigned to signed integer calculator cost?

The browser tool is free and runs locally.

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/dev/unsigned-to-signed

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/dev/unsigned-to-signed \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"value":255,"bits":8}'
{
  "value": 255,
  "bits": 8
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "dev.unsigned_to_signed",
  "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.

Successful API calls use the published base price of $0.002 per item.

How unsigned-to-signed two's complement reinterpretation works

The implementation uses exact integer arithmetic with no floating-point rounding, no random seeds, no wall-clock timestamps, and no network calls, so identical inputs always produce identical JSON.

Input contract, response shape, and error behaviour

Classic checks include value two hundred fifty-five with eight bits mapping to signed negative one and binary all ones; value one hundred twenty-eight with eight bits mapping to signed negative one hundred twenty-eight; and value forty-two with sixteen bits remaining positive forty-two with leading zeros. If you need to encode a signed integer into a bit string or decode a bit string you already have, use a dedicated two's complement converter landing rather than overloading this unsigned-to-signed reinterpret contract. POST a JSON body with two required fields: value, a non-negative integer to reinterpret, and bits, the word width from two through fifty-three. Value may arrive as a JSON number or as a digit string with an optional leading plus; aliases u, unsigned, n, and number are accepted. Bits may arrive as a number or digit string; aliases width, bit_width, nbits, and w are accepted. Missing fields, empty strings, NaN, Infinity, fractional values, negative values, widths outside two through fifty-three, and values greater than two to the power of bits minus one fail with invalid_input and are not charged. On success the body echoes value and bits, returns signed (the two's-complement reading), unsigned (the same non-negative residue), binary (exactly bits characters of zero and one, high bit on the left), high_bit_set and is_negative booleans, the legal signed min and max for the width, unsigned_max, and method set to twos_complement_reinterpret. Pricing for successful API calls is the published base of $0.002 per item; validation failures do not consume prepaid balance.

Where unsigned-to-signed calculators earn their keep

Computer science and digital design courses introduce two's complement when students first meet signed registers and the surprise that a large unsigned byte can mean a small negative number under a signed cast; a trusted oracle that returns the signed value, the bit pattern, and a high-bit flag speeds answer keys and lab demos without fragile spreadsheet formulas. Embedded firmware and protocol documentation list sensor fields stored as unsigned dumps in logs that must be re-read as signed offsets or temperature deltas at eight or sixteen bits, so reviewers can verify the sign bit at a glance. Compiler and language-runtime notes explain how C, Java, and Rust cast uint8 or uint16 to the matching signed type by reinterpreting bits; tutors compare student cast helpers against a known-good signed result for zero, the midpoint, the maximum unsigned, and all ones. Because this capability is a pure parse engine, API pricing is the published base of $0.002 per successful item and failed validation does not consume balance. Treat bidirectional signed-integer-to-binary conversion, hex-only dumps, IEEE floating-point bit patterns, and sign-extension across unequal widths as separate search intents with their own landings rather than stretching this unsigned-to-signed calculator past its honest scope.

Test fixtures for cast helpers

Generate golden signed values and bit patterns for unit tests of language cast helpers without hand-computing two's complement residues.

Read the full KIT documentation →