NUMBER REPRESENTATION

Checking the source base before converting a digit string

The string 10 names two in base two, ten in base ten and sixteen in base sixteen. This guide shows how to confirm the source base before you convert a digit string, and what the converter can and cannot read.

One spelling, several numbers

A digit string is a recipe, and the base is the measuring cup. Without it the characters carry no quantity. The string 10 is the clearest case: it always means one group of the base followed by zero units, so it equals the base itself. In base two it is two, in base eight it is eight, in base ten it is ten and in base sixteen it is sixteen. Nothing in the spelling tells you which reading the author intended. People usually notice the problem only when two systems disagree, for example when a log file shows one value and a spreadsheet import shows another. The fix is to carry the base label with the digits every time they are copied, exported or quoted in a message.

How a digit string is read

The converter parses a signed digit string with repeated multiply-add, using BigInt arithmetic. Start with zero. For each digit from left to right, multiply the running value by the source base and add the digit. For 101 in base two the steps are 0 × 2 + 1 = 1, then 1 × 2 + 0 = 2, then 2 × 2 + 1 = 5. The same three characters in base eight go 1, 8, 65, and in base sixteen they go 1, 16, 257. The target base only matters afterward, when the value is written back out by repeated division. Because the parsing step depends on the source base alone, a wrong source label corrupts everything downstream, however carefully the target base is chosen.

The two default cases side by side

The worked cases below the article hold the digits 10 and the target base ten, and change only the source base. With source base two the converter returns 2, because the left digit has a place value of two. With source base ten it returns 10, because the same spelling now names ten. Try a third pair yourself: source base sixteen returns 16, and source base three returns 3. Every case follows the same rule, a leading 1 followed by a single 0 equals the base. Use this as a quick sanity check on the page: if the output for 10 ever differs from the source base you selected, the control is not set the way you think it is.

Strings that fit many bases

A string made only of the digits 0 and 1 is valid in every base from two upward, which is why binary-looking values are easy to misread. The string 101 is five in base two, 65 in base eight, 101 in base ten and 257 in base sixteen. Similarly, 755 cannot be binary because it contains digits above 1, but it is valid in base eight, where it equals 7 × 64 + 5 × 8 + 5 = 493, and in base ten, where it is simply 755. Unix file permissions are written in octal for this reason. When a string could belong to several bases, look at the surrounding context: a column header, a file format specification or the program that produced it usually settles the question.

Letters as digits in bases above ten

Bases eleven through thirty-six continue past 9 with letters, so a stands for ten, b for eleven and z for thirty-five. The hexadecimal string ff is 15 × 16 + 15 = 255, the largest value of a single byte. In base thirty-six, zz is 35 × 36 + 35 = 1,295. A digit equal to or larger than the base cannot appear in a valid string for that base, so 2 is not a binary digit and g is not a hexadecimal digit. That gives you a free diagnostic: if a string contains a letter beyond f, a hexadecimal reading is ruled out. Conventions for letter case vary between systems, so keep the original spelling when you record a value.

Signs, prefixes and fractional points

The tool accepts signed integers, so -101 in base two converts to -5. It does not interpret a fractional point, so a value such as 10.1 is outside its scope. It also does not recognize programming-language prefixes. Notations such as 0x1F for hexadecimal or 0b101 for binary carry the base inside the string in some languages, but the converter expects the plain digits and a separate base control. Remove the prefix, select the matching source base, and then convert. Treat a leading zero the same way: in some languages 017 means octal, whereas here the digits are read in whatever base you select, and leading zeros add nothing to the value.

Where mislabeled bases show up

Color codes are one everyday example. The web color FF8800 is three base-sixteen pairs, with FF equal to 255 for red, 88 equal to 136 for green and 00 for blue. Reading the same pairs as decimal would give nonsense. Identifiers, checksums and memory addresses are often hexadecimal, while permission masks are octal and hardware flags are binary. Spreadsheets add a trap of their own, because a cell that looks like a number may be stored as text or converted by the import. When you receive a value from someone else, ask for the base in writing, and when you send one, write it as 1010 (base 2) rather than relying on the reader to guess.

Large values and the output base

Ordinary floating-point arithmetic loses integer precision above 9,007,199,254,740,992, which is 2 to the 53rd power. The converter uses BigInt, so larger integers keep every digit. The decimal value 18,446,744,073,709,551,616, which is 2 to the 64th power, converts to 1 followed by sixteen zeros in hexadecimal. The same BigInt approach applies in the other direction, and a long binary string can be moved into base thirty-six to shorten it. The output base is a display choice and never changes the number, only its spelling. If a converted result looks wrong, convert it back with the base pair reversed. A round trip that returns the original string, apart from leading zeros, confirms both the digits and the bases.

A short routine before converting

Before pressing convert, run three quick checks. First, find the largest digit in the string and make sure the source base is greater than it, since a base of ten cannot contain the letter a and a base of sixteen cannot contain g. Second, look for a prefix or suffix such as 0x, a trailing h or a subscript, and strip it after noting what it says. Third, estimate the answer roughly: a three-character string in base sixteen should land under 4,096, while the same three characters in base two stay below 8. If the output falls far outside that rough range, the source base is probably wrong.

Reproduce the checks

Source base two

Open the Integer Base Converter and enter:

Value
10
Source base
2
Target base
10

Expected output:

Value

2

The left digit has a place value of two.

Source base ten

Open the Integer Base Converter and enter:

Value
10
Source base
10
Target base
10

Expected output:

Value

10

The same source spelling now names ten.

References and implementation scope

The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.

Sources

Related tasks