Base Converter

Any base 2–36, fractions, and two's complement β€” with the working shown.

Input

From to

Answer

β€”

The same value in the usual bases

The working

Reference

The two procedures

Base b β†’ decimal. Positional expansion: every digit is worth its face value times the base raised to its position, counting from 0 at the right.

N₁₀ = Ξ£ dα΅’ Γ— b^i for i = 0 … nβˆ’1 1101β‚‚ = 1Γ—2Β³ + 1Γ—2Β² + 0Γ—2ΒΉ + 1Γ—2⁰ = 8 + 4 + 0 + 1 = 13

Decimal β†’ base b. Repeated division. Divide by b, write down the remainder, repeat on the quotient until it reaches 0 β€” then read the remainders upward.

13 Γ· 2 = 6 r 1 ↑ 6 Γ· 2 = 3 r 0 β”‚ read 3 Γ· 2 = 1 r 1 β”‚ upward 1 Γ· 2 = 0 r 1 β”‚ β†’ 1101β‚‚

The fraction. Repeated multiplication, the mirror image. Multiply by b, take the whole part as the next digit, repeat on what is left β€” and read downward.

0.625 Γ— 2 = 1.25 β†’ 1 0.250 Γ— 2 = 0.50 β†’ 0 0.500 Γ— 2 = 1.00 β†’ 1 β†’ .101β‚‚
The shortcut, and when it applies

When both bases are powers of two, do not go via decimal. The bits line up: three to an octal digit, four to a hex digit. Group them and read off.

1101 1010β‚‚ β†’ D A₁₆ (no arithmetic at all) 111 101 101β‚‚ β†’ 7 5 5β‚ˆ

This is the method networking uses on a MAC address and on every IPv6 field, and it is what an exam is asking for when it says "convert". Going via decimal gets the same answer with working nobody uses.

Two's complement

A negative number has no minus sign in a register β€” it has a width and a pattern. At width n:

encode: P = 2ⁿ + x for x < 0 decode: x = P βˆ’ 2ⁿ if the top bit is set P otherwise range: βˆ’2ⁿ⁻¹ … 2ⁿ⁻¹ βˆ’ 1

Invert-and-add-one is the same operation, and it is the one written by hand:

-13 at 8 bits 13 = 0000 1101 invert = 1111 0010 (one's complement) add 1 = 1111 0011 β†’ 0xF3 check: 256 + (βˆ’13) = 243 = 0xF3 βœ“

The same eight bits are 243 unsigned and βˆ’13 signed. Nothing in the bits says which β€” the width and the mode do. Above, decimal is the value and every other base shows the stored pattern.

Powers of two

The table you end up memorising. 2¹⁰ is the one to anchor on; every subnet mask and every host count comes off it.

What this accepts

Prefixes 0b 0o 0d 0x, and the separators _, spaces and : anywhere β€” plus - inside a hex number, because MAC addresses are written 00-1B-44.

Digits are 0-9 then A-Z, which runs out at base 36. Anything above that needs a bracket notation like [12].[35].[7], which is a different tool, so this one refuses rather than inventing one.

A digit that does not belong to the base is named, with its position, instead of being quietly parsed into something else.