تخطَّ إلى المحتوى
DevTools / محوّل أنظمة الأعداد

محوّل أنظمة الأعداد

Converting between number bases is arithmetic, but most of the difficulty is in the edge cases: a 64-bit value that loses precision the moment a JavaScript Number touches it, a negative number whose hexadecimal form depends on the word size you assume, a byte string that is really a float. This converter works in arbitrary precision using BigInt so a 128-bit value round-trips exactly, supports every base from 2 to 36 plus Base32, Base58, Base62 and Base64, and shows the same value as an 8, 16, 32 or 64-bit word in signed and unsigned interpretations with bit length, population count and IEEE-754 reinterpretation.

تعمل بالكامل داخل المتصفح — لا يُرفع أي شيء.

Radix prefixes (0x, 0b, 0o) and separators (spaces, underscores, commas) are stripped automatically.

Binary0b1101 1110 1010 1101 1011 1110 1110 1111
Octal0o33 653 337 357
Decimal3 735 928 559
Hexadecimal0xdead beef
Base3232W 353Y
Base361ps9wxb
Base586h8cQN
Base6244pZgF
Base643q 2+7w

32-bit view

Two’s complement (unsigned)
3735928559
Signed value
Does not fit in 32 bits
Bit length
32
Byte length
4
Set bits
24
As IEEE-754 float32
—
As IEEE-754 float64
1.8457939563e-314
Printable bytes
—

Float views reinterpret the raw bits, which is why 0x40490fdb reads as 3.1415927410125732.

كيف تعمل

Positional notation is the same algorithm in every base: the value is the sum of each digit multiplied by the base raised to the digit's position. Converting from decimal to another base extracts digits by repeated division and remainder, and converting into decimal accumulates by repeated multiplication and addition. The reason this is worth doing with BigInt rather than with ordinary numbers is that JavaScript numbers are IEEE-754 doubles with 53 bits of exact integer precision, so a 64-bit value such as a Twitter snowflake ID or a large hash silently loses its low bits the moment it is parsed — 9007199254740993 becomes 9007199254740992, and the corruption is invisible until the value fails to match.

Negative numbers have no single hexadecimal representation; the word size decides. In a 32-bit two's complement scheme, minus one is FFFFFFFF, while in 64 bits the same value is FFFFFFFFFFFFFFFF, and in 8 bits it is FF. All three are correct and none is meaningful without knowing the width. This is not a theoretical concern: a protocol that specifies a signed 32-bit field, a checksum computed over 16-bit words and a file format storing 64-bit little-endian integers will each expect a different rendering. The bit-width view makes the choice explicit and shows signed and unsigned readings side by side.

Bit-level interpretation is what turns a conversion tool into a debugging tool. Bit length tells you how many significant bits a value has, which reveals whether a flag was set or a value overflowed its intended field. Population count — the number of set bits — is used in hash quality checks and error-correcting codes. Reading the same 32 bits as an IEEE-754 float is how you discover that a value of 1065353216 in a register is actually 1.0, a trick that comes up constantly when reverse-engineering a binary format or debugging a serialisation mismatch.

The alphabet-based encodings are a different family and are included because they are routinely confused with the numeric ones. Base32, Base58, Base62 and Base64 encode a byte string rather than a number, using a fixed character set to make binary data safe for transport. Base58 in particular omits the characters that look alike in print — zero, capital O, capital I, lowercase l — which is why Bitcoin addresses use it and why a base-58 string pasted from a screenshot is less likely to be mistyped. What they have in common with a base conversion is only the idea of a positional alphabet.

حالات الاستخدام الشائعة

  • Convert a hex colour, memory address or bitmask to decimal and back.
  • Read a 64-bit identifier from a log file without losing precision to a floating-point conversion.
  • Work out what a negative number looks like as a signed hexadecimal value at a specific word size.
  • Interpret a register value as an IEEE-754 float to check a serialisation format.
  • Convert a permissions bitmask to binary to see which individual bits are set.
  • Encode a byte string in Base58 or Base62 for a system that uses a compact alphabet.

آخر تحديث: 2026-10-14 — يُعرض متن المقال بالإنجليزية، بينما الواجهة مترجمة.

الأسئلة الشائعة

Why does converting my large number give a slightly wrong result?

Because it passed through a JavaScript Number, which is an IEEE-754 double and can represent integers exactly only up to 2^53 — about 9 quadrillion. Beyond that, the least significant bits are rounded away and the value silently changes. This affects snowflake IDs, large hashes and 64-bit database keys. This converter uses BigInt throughout, so it handles values of arbitrary size exactly; the distortion happens in other tools, and in any code that calls parseInt on a big integer.

Why is the hexadecimal for a negative number different in different tools?

Because they assume different word sizes. Two's complement representation depends entirely on the width: minus one is FF in 8 bits, FFFF in 16, FFFFFFFF in 32 and FFFFFFFFFFFFFFFF in 64. All are correct. Pick the width that matches the field you are working with — a protocol specification or a file format will state it — and be aware that a converter which silently assumes 32 bits will produce a value that is wrong by construction when the field is 64 bits wide.

How do I tell if a hex value is a float?

By reinterpreting the bits. An IEEE-754 single-precision float is 32 bits: one sign bit, eight exponent bits and 23 mantissa bits. Reading the integer 1065353216 as a float gives 1.0, and 1078530011 gives approximately pi. This matters when a binary protocol or a serialised structure stores floats and you are looking at a hex dump: a value that looks like an arbitrary large integer may be a perfectly ordinary decimal number that has been reinterpreted. The bit view here shows both readings of the same 32 bits.

What is the difference between base 16 and Base64?

They are different kinds of thing that happen to share vocabulary. Base 16 is a number base: it is positional notation, and a hexadecimal number denotes an exact quantity. Base64 is a byte encoding: it takes an arbitrary sequence of bytes and maps every three of them to four printable characters, so that binary data can travel through a text-only channel. Converting a number to base 16 preserves its value; encoding bytes as Base64 preserves their content. Confusing the two is why a hash is sometimes described as a base-16 number when it is really a byte string that is conventionally displayed in hex.

أدوات ذات صلة