keisoku

Base-N Number Converter

Convert between binary, octal, decimal and hexadecimal, plus any base from 2 to 36. See your value listed in every common base at once.

Last updated:

Input

Input base
Output base (common values)

Result

Representation in Base 2 (binary)

11111111

Input: Base 10 (decimal) (decimal 255)

Base 2 (binary)

11111111

Base 8 (octal)

377

Base 10 (decimal)

255

Base 16 (hexadecimal)

ff

BasePrefixRepresentation
Base 20b11111111
Base 80o377
Base 10—255
Base 160xff

How it works

  • Pick an input base and an output base, then enter the number to convert. Along with the representation in your chosen base, you also see the binary, octal, decimal and hexadecimal values at the same time.
  • For bases above 16, digits from 10 upward are written with letters (a-z). Input accepts either uppercase or lowercase, and results are shown in lowercase.
  • Add a minus sign in front to treat the value as negative; the sign is carried into the result. When the value is 0 no sign is shown.
  • To make long numbers easier to read, you may include underscores (_), commas (,) or spaces in the input. They are stripped automatically before calculation.
  • Decimals and exponential notation are not supported; enter integers only. If you type a digit that does not belong to the selected base, an error is shown.
  • Calculations use arbitrary-precision integers internally, so even very large numbers that would lose accuracy on an ordinary calculator are converted correctly.

Converting by hand

To turn a decimal number into binary, divide by 2 repeatedly and write down the remainders, then read them from last to first. For 202: 202 ÷ 2 = 101 r 0, 101 ÷ 2 = 50 r 1, 50 ÷ 2 = 25 r 0, 25 ÷ 2 = 12 r 1, 12 ÷ 2 = 6 r 0, 6 ÷ 2 = 3 r 0, 3 ÷ 2 = 1 r 1, 1 ÷ 2 = 0 r 1. Reading upward gives 11001010. The same method works for any base: divide by 8 for octal, by 16 for hex.

Going back, multiply each digit by its place value and add. In binary the place values from the right are 1, 2, 4, 8 and so on, so 11001010 is 128 + 64 + 8 + 2 = 202. Between binary and hex there is a shortcut: split the bits into groups of four from the right. 1100 is 12 (c) and 1010 is 10 (a), so 202 is ca in hex. Octal works the same way with groups of three.

Where these conversions come up

Base conversion shows up in plenty of everyday technical tasks, not just programming exercises.

  • Web colors: #1E90FF is three separate bytes. Converting 1E, 90 and FF one at a time gives rgb(30, 144, 255). Entering all six digits at once returns one large number instead.
  • File permissions: chmod 755 is an octal number. In binary it is 111101101, and the three groups 111, 101, 101 map to rwx, r-x, r-x. 644 becomes 110100100, which is rw-r--r--.
  • Subnet masks: 255.255.255.192 has a last octet of 11000000 in binary, so the mask has 24 + 2 = 26 one-bits and is written /26.
  • Unicode: the code point U+00E9 (é) is hex e9, which is 233 in decimal.
  • Limits: n bits hold values up to 2 to the n minus 1, so 8 bits max out at 255 (ff) and 16 bits at 65,535 (ffff).

Input pitfalls

Leave out programming prefixes such as 0x, 0b and 0o. Typing 0xff with the input base set to 16 produces an error, because x is not a hex digit. Base 36 is a trickier case: there x is a valid digit worth 33, so 0x1f is accepted and silently read as the decimal value 42,819.

Results never show leading zeros. If you need a fixed width, such as a full byte, pad on the left yourself: 5 is 101 in binary and 00000101 as an 8-bit value. Separators like underscores, commas and spaces are ignored on input, so 1111_0000 is fine.

Negative numbers and two's complement

This tool shows a negative number as a minus sign in front of its magnitude, so -5 is -101 in binary. Computers usually store signed integers in two's complement instead. To get the n-bit two's complement form of a negative number, enter 2 to the n minus its absolute value: for -5 in 8 bits, enter 256 - 5 = 251, which converts to 11111011. For -1 in 32 bits, enter 4,294,967,295 to get ffffffff.

To read a bit pattern as a signed value, check the leftmost bit. If it is 0, the number is positive and converts directly. If it is 1, convert it as usual and subtract 2 to the n: 11111011 is 251, and 251 - 256 = -5.

Frequently asked questions

How do I convert binary to hexadecimal here?
Set the input base to 2 (binary) and the output base to 16 (hex), then enter your value. Besides the chosen base, the tool also shows the binary, octal, decimal, and hexadecimal representations at once.
How are digits shown for bases larger than 16?
For bases above 16, digit values of 10 and up are written as letters (a–z). Input accepts either upper or lower case, and results are displayed in lower case. Any base from 2 to 36 is supported.
Can it handle decimals or very large numbers?
Decimals and exponential notation are not supported, so only integers can be entered. Internally it uses big-integer arithmetic, so even very large integers that would lose precision on an ordinary calculator convert exactly.

Reviews

Tell us what you think of this calculator.

Write a review

Found an incorrect result or a problem? Turn this on to report it.

Rating

  1. Home
  2. Hobby
  3. Base-N Number Converter