Skip to content
cosmodev ~/tools/number-base

مبدل مبنای عدد

Converters & Formatters

تبدیل اعداد بین مبنای دو، هشت، ده و شانزده. مبتنی بر BigInt، پس مقادیر دلخواه بزرگ را بدون از دست رفتن دقت مدیریت می‌کند.

خروجی (مبنا 16)
ff
همه مبناها
b211111111
b8377
b10255
b16ff
b327v
b3673

(مستندات به انگلیسی)

What it does

Converts numbers between binary (2), octal (8), decimal (10), and hexadecimal (16). It is powered by BigInt, so values of any size convert exactly - a 300-digit decimal or a 64-bit 0xffffffffffffffff loses nothing to floating-point precision (the fate of plain Number converters past 2^53).

The parser is forgiving where it helps: 0x/0b/0o prefixes are accepted when they match the source base, letters work in any case, leading +/- signs are honored, and surrounding whitespace is trimmed. A digit that is illegal for the source base (like f in decimal) is rejected with a clear error instead of a wrong answer. 100% client-side.

How to use it

  1. Pick the source base with the left segmented control (BIN / OCT / DEC / HEX).
  2. Pick the target base with the right segmented control.
  3. Click the swap button between them to reverse the conversion direction in one tap.
  4. Type or paste the number into Input - the result appears immediately in Output.
  5. Click Copy on the output to grab the converted value.
  6. Read the All bases panel under the converter: the parsed value shown live in bases 2, 8, 10, 16, 32, and 36 at once, each row with its own copy button. It reads the input in the source base and disappears when the input does not parse.
  7. Fix invalid input when the tool flags it: an illegal digit for the source base shows “Invalid digit for base N” in place of the output.

You can also open the tool pre-loaded via URL parameters: ?v=<value>&from=<base>&to=<base> (e.g. /tools/number-base?v=255&from=10&to=16).

Examples

Verified by running convertBase() from src/lib/numberBase.ts (the exact function the tool uses):

255  in DEC → HEX:   ff
255  in DEC → BIN:   11111111
255  in DEC → OCT:   377
ff   in HEX → DEC:   255          (0xff also works)
0b1010 in BIN → DEC: 10
-ff  in HEX → BIN:   -11111111    (sign carries through)
ff   in DEC → —      error: "Invalid digit for base 10"

Arbitrary precision - where Number-based converters fail silently:

18446744073709551615 DEC → HEX:  ffffffffffffffff          (2^64 − 1, exact)
deadbeefcafebabe     HEX → DEC:  16045690984503098046      (64-bit pattern, exact)
2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397376
  DEC → HEX:  1000000000000000000000000000000000000000000000000000000000000000000000000000
  (a 79-digit decimal → 76 hex digits, digit-for-digit exact)

Good to know

  • Private: conversion runs entirely in your browser.
  • Bases are limited to 2, 8, 10, 16 in the UI. The underlying parser handles every base 2-36, but only these four are exposed.
  • The 0x/0b/0o prefix only strips when it matches the source base. 0b1010 under BIN is 10; the same text under HEX parses as the hex digits 0b1010 (= 725008), and 0x1f under DEC is rejected as an invalid digit (x is not a decimal digit).
  • Negative numbers convert with their sign; there is no two’s-complement mode.
  • Related tools: Bitwise Calculator, Hex ↔ Text Converter, Base32 / Base58 / Base62 / Base85 Encoder
کد منبع14 زبان

100% سمت کاربر · داده‌های شما هرگز از مرورگرتان خارج نمی‌شود. به کارتان آمد؟ آن را با یک همکار به اشتراک بگذارید.