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 >>> 0gives 4294967295 — the unsigned shift reinterprets the same bits as positive.2147483647 + 1 | 0gives −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.
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
755is 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.
