Skip to tool
ecech.
💻 Developer & Code

Base Converter That Shows What Negative Numbers Actually Look Like in Memory

\u22125 is 11111011 in 8 bits and 11111111111111111111111111111011 in 32. Neither is more correct — the width is part of the answer.

Decimal

Hexadecimal

Octal

Binary

Bits

Other bases

Advertisement

How the calculation works

−5, stored three ways, all correct on paper -101 a minus sign; no computer stores this 8-bit two's complement 11111011 fits a byte 32-bit two's complement 11111111111111111111111111111011 The width is not a display setting. It is part of what the number is.

How to Use This Tool

Type a value and say which base it is in. Everything else updates, including the bit-level view at the width you choose.

Two's complement, and why width matters

Computers do not store a minus sign. A negative number is represented in two's complement: invert every bit of the positive value and add one. The leftmost bit then acts as a sign, and arithmetic works without any special case for negatives, which is the whole reason the scheme won.

The consequence is that a negative number has no single binary form. −5 is 11111011 in 8 bits and 11111111111111111111111111111011 in 32, because the padding is ones rather than zeros. A converter that shows you one without asking the width has picked for you.

What JavaScript does, measured

Worth knowing if you write any bit manipulation, because it catches people out:

  • Bitwise operators coerce to 32-bit signed integers, whatever the number was.
  • -5 >>> 0 gives 4294967295 — the unsigned shift reinterprets the same bits as positive.
  • 2147483647 + 1 | 0 gives −2147483648, because the sign bit was reached and the value wrapped.

So |0 is a common trick for truncating to an integer, and it silently breaks above about two billion. For larger values, BigInt and its own operators are the way, and they do not wrap.

Why hex and not decimal for bit patterns F F each digit is exactly four bits 1111 1111 so you can read the bits straight off Decimal 255 tells you nothing about which bits are set. Hex FF tells you immediately, which is why colours, masks and memory are written in hex.
One hex digit is four bits exactly, and one octal digit is three.

Where each base turns up

  • Hexadecimal — colours (#FF5733), memory addresses, hashes, byte values. One digit per four bits makes bit patterns readable.
  • Binary — flags, permissions, network masks, anywhere individual bits carry meaning.
  • Octal — largely historical, surviving mainly in Unix file permissions, where 755 is three groups of three bits.
  • Base 36 — digits plus letters, used for short identifiers because it packs more into fewer characters.

A trap in other languages

A leading zero means octal in C, and historically in JavaScript too. So 010 is 8, not 10. Modern JavaScript rejects it in strict mode and uses 0o10 instead, but the old form still appears in configuration files and in other languages. If a number is behaving as though it were smaller than written, a leading zero is worth checking.

Advertisement

Frequently Asked Questions

How do you write a negative number in binary?
In two's complement: invert every bit of the positive value and add one. There is no minus sign, and the answer depends on the width — −5 is 11111011 in 8 bits and 11111111111111111111111111111011 in 32, because the padding is ones. A converter showing one form without asking the width has chosen for you.
What is two's complement?
The representation almost every computer uses for signed integers. Its advantage is that addition and subtraction work identically for positive and negative values with no special case, which is why it replaced earlier schemes like sign-and-magnitude.
Why does -5 >>> 0 give 4294967295 in JavaScript?
Because bitwise operators coerce to 32-bit integers, and the unsigned right shift reinterprets the same bit pattern as an unsigned value. The bits did not change; only the reading of the sign bit did.
Why does |0 break on large numbers?
Because it coerces to a 32-bit signed integer, so anything above 2,147,483,647 wraps around to negative. 2147483647 + 1 | 0 gives −2147483648. It is a common integer-truncation trick and it fails silently above about two billion — use BigInt or Math.trunc for larger values.
Why is hexadecimal used instead of decimal?
Because one hex digit is exactly four bits, so you can read a bit pattern straight off the digits. Decimal 255 tells you nothing about which bits are set; FF tells you all eight are. That is why colours, memory addresses and bitmasks are written in hex.
Why does 010 sometimes mean 8?
A leading zero indicates octal in C and in older JavaScript, so 010 is 8. Modern JavaScript rejects it in strict mode in favour of 0o10, but the old form still appears in config files and other languages. If a number behaves as though it were smaller than written, check for a leading zero.

Related tools in Developer & Code

Browse all Developer & Code tools
The person who builds ecech., at the desk where the tools are written.

Made by one person

ecech. is not a content farm. Every tool here is written and checked by hand, one at a time, by someone who wanted the tool to exist and could not find a version that showed its working.

No accounts and no sign-in, and nothing you type reaches a server — every calculation on this page runs inside your browser. The ads are served by Google and do set their own cookies, which is set out in full on the privacy page. More about the site.