Introduction

A number system of radix (base) rr represents each value as a weighted sum of powers of rr, with digit symbols drawn from {0,1,…,r−1}\{0, 1, \ldots, r-1\}. Digital hardware uses radix 2 because two voltage levels are reliable; humans prefer radix 10; programmers also use radix 8 (octal) and radix 16 (hexadecimal) as compact notations for binary bit patterns.

This topic covers conversions between bases, the bit width needed for a given range, and the binary expansion of fractions. Signed encodings and IEEE floating point build on these facts; they are treated in separate notes.

Prerequisites

  • Place-value arithmetic and integer powers; no prior digital-logic note is required.

Core concepts

Positional notation

An nn-digit integer in radix rr

(dn−1dn−2…d1d0)r(d_{n-1}d_{n-2}\ldots d_1 d_0)_r

has decimal value

∑i=0n−1di ri,0≤di<r.\sum_{i=0}^{n-1} d_i\, r^{i}, \qquad 0 \le d_i < r.

A fractional part (0.d−1d−2…d−m)r(0.d_{-1}d_{-2}\ldots d_{-m})_r contributes ∑k=1md−k r−k\sum_{k=1}^{m} d_{-k}\, r^{-k}.

RadixNameDigit alphabetTypical use
2Binary0, 1Hardware, memory, buses
8Octal0 to 7Compact groups of 3 bits
10Decimal0 to 9Human I/O
16Hexadecimal0 to 9, A to FCompact groups of 4 bits

Hexadecimal digits. A =10= 10, B =11= 11, C =12= 12, D =13= 13, E =14= 14, F =15= 15. Case does not matter for the value.

Valid-digit rule. A numeral is legal in radix rr only if every digit is less than rr. So the smallest radix in which a numeral can be read is max⁡(2,1+largest digit)\max(2,1+\text{largest digit}): (2071)r(2071)_r needs r≥8r \ge 8, and a numeral containing the digit 9 can never be octal. Every unknown-radix question starts by writing down this lower bound.

Range of nn digits in radix rr. The nn-digit numerals in radix rr are exactly 00 to rn−1r^n - 1, so there are rnr^n of them. If leading zeros are forbidden, there are (r−1) rn−1(r-1)\,r^{n-1} numerals with exactly nn digits; for example, 6⋅72=2946 \cdot 7^2 = 294 three-digit numerals in base 7.

Why powers of two matter

Because 23=82^3 = 8 and 24=162^4 = 16, every three bits map to one octal digit and every four bits map to one hex digit, with no leftover. That is why octal and hex are lossless shorthands for binary, while decimal is not.

Useful powers of two:

kk2k2^kkk2k2^k
018256
129512
24101024
38124096
4161665536
53220about 10610^6
66430about 10910^9
712832about 4⋅1094\cdot 10^9

Range of an unsigned nn-bit word

With nn bits you can represent exactly 2n2^n distinct patterns, namely the integers 0,1,…,2n−10, 1, \ldots, 2^n - 1. To represent NN distinct values you need at least ⌈lg⁡N⌉\lceil \lg N \rceil bits. For N=1000N = 1000, ⌈lg⁡1000⌉=10\lceil \lg 1000 \rceil = 10 because 29=512<1000≤1024=2102^9 = 512 < 1000 \le 1024 = 2^{10}.

How it works

Integer: radix rr to decimal

Expand by powers. Example: (234)8=2⋅82+3⋅81+4⋅80=128+24+4=15610(234)_8 = 2\cdot 8^2 + 3\cdot 8^1 + 4\cdot 8^0 = 128 + 24 + 4 = 156_{10}. Same method for any radix.

Integer: decimal to radix rr (repeated division)

Repeatedly divide by rr and record remainders. They are generated least significant first; read bottom to top to obtain digits most significant to least significant.

Example. Convert 15610156_{10} to binary:

DivisionQuotientRemainder
156/2156 / 2780
78/278 / 2390
39/239 / 2191
19/219 / 291
9/29 / 241
4/24 / 220
2/22 / 210
1/21 / 201

Reading remainders bottom to top: 15610=(10011100)2156_{10} = (10011100)_2. The same procedure with divisor 8 gives (234)8(234)_8; with divisor 16 gives (9C)16(9\text{C})_{16}.

Repeated division and multiplication methods for base conversion
Figure 1. Left: converting 15610156_{10} to binary by repeated division by 2. Right: converting the fraction 0.625100.625_{10} to binary by repeated multiplication by 2.

Binary to octal or hex (grouping)

  • Binary to octal: group bits in threes from the binary point outward; pad with leading or trailing zeros if needed. 100111002=010 011 100=(234)810011100_2 = 010\,011\,100 = (234)_8.
  • Binary to hex: group in fours. 1001 11002=(9C)161001\,1100_2 = (9\text{C})_{16}.
  • Octal or hex to binary: expand each digit to 3 or 4 bits.
  • Fractions group the same way, starting at the point and moving right, padding with trailing zeros: 0.1012→(0.5)80.101_2 \to (0.5)_8 and 0.10102→(0.A)160.1010_2 \to (0.\text{A})_{16}.
  • Mixed example: 10111.0112=010 111.011=(27.3)810111.011_2 = 010\,111.011 = (27.3)_8 and 0001 0111.0110=(17.6)160001\,0111.0110 = (17.6)_{16}. Both equal 23.3751023.375_{10}.

Between two non-decimal radices

If both radices are powers of a common base, grouping applies. When one radix is a power of the other, R=rkR = r^k, group kk radix-rr digits per radix-RR digit, exactly as for binary and hex. When they share a common base but neither is a power of the other, as with octal and hex (84=1638^4 = 16^3), group through that base, or map 4 octal digits directly to 3 hex digits. Otherwise go through decimal.

Example. (2120)3(2120)_3 to base 9: since 9=329 = 3^2, group pairs from the right: 21∣2021 \mid 20. Then (21)3=7(21)_3 = 7 and (20)3=6(20)_3 = 6, so (2120)3=(76)9(2120)_3 = (76)_9. Check: 2⋅27+1⋅9+2⋅3+0=692\cdot 27 + 1\cdot 9 + 2\cdot 3 + 0 = 69 and 7⋅9+6=697\cdot 9 + 6 = 69.

Example. (725)8(725)_8 to hex: octal digits to bits 111 010 101111\,010\,101, regroup in fours from the right 0001 1101 01010001\,1101\,0101, so (725)8=(1D5)16=46910(725)_8 = (1\text{D}5)_{16} = 469_{10}.

Example. (7255)8(7255)_8 to hex by mapping 4 octal digits to 3 hex digits, because 84=1638^4 = 16^3: 72558=111 010 101 1012=1110 1010 11012=(EAD)16=3757107255_8 = 111\,010\,101\,101_2 = 1110\,1010\,1101_2 = (\text{EAD})_{16} = 3757_{10}.

Fraction: decimal to binary (repeated multiplication)

Multiply the fractional part by 2; the integer part of the product is the next bit; repeat on the new fractional part. Stop when the fraction becomes 0 or when enough bits are obtained.

Example. 0.625100.625_{10}: 0.625×2=1.250.625\times 2 = 1.25 (bit 1), 0.25×2=0.50.25\times 2 = 0.5 (bit 0), 0.5×2=1.00.5\times 2 = 1.0 (bit 1). So 0.62510=0.10120.625_{10} = 0.101_2.

Recurring fractions. Many finite decimals are infinite in binary. The fraction 0.1100.1_{10} yields the repeating bit string 0.0001100110011…20.0001100110011\ldots_2. The first eight bits after the point are 0001100100011001. Hardware therefore stores an approximation. For inexact computations where approximate agreement is intended, use suitable absolute/relative tolerances; exact equality is appropriate when the specification requires it (see Floating-Point Representation).

Fraction: binary to decimal

Sum bit weights: 0.1012=1⋅2−1+0⋅2−2+1⋅2−3=0.5+0.125=0.625100.101_2 = 1\cdot 2^{-1} + 0\cdot 2^{-2} + 1\cdot 2^{-3} = 0.5 + 0.125 = 0.625_{10}.

Arithmetic in radix rr

Addition works column by column as in decimal: when a column sum ss reaches rr or more, write s−rs - r and carry 1 (a column sum can never exceed 2r−12r - 1, so the carry is at most 1).

  • Hex: (A7)16+(5C)16(\text{A}7)_{16} + (5\text{C})_{16}. Column 0: 7+12=19=16+37 + 12 = 19 = 16 + 3, write 3, carry 1. Column 1: 10+5+1=1610 + 5 + 1 = 16, write 0, carry 1. Result (103)16(103)_{16}. Check: 167+92=259=256+3167 + 92 = 259 = 256 + 3.
  • Octal: (647)8+(156)8(647)_8 + (156)_8. Columns give 13=8+513 = 8 + 5, then 4+5+1=10=8+24 + 5 + 1 = 10 = 8 + 2, then 6+1+1=86 + 1 + 1 = 8. Result (1025)8(1025)_8. Check: 423+110=533=512+16+5423 + 110 = 533 = 512 + 16 + 5.

Radix complements

For an nn-digit number NN in radix rr:

  • The diminished radix complement ((r-1)'s complement) is (rn−1)−N(r^n - 1) - N. It is formed digit by digit: replace each digit dd by (r−1)−d(r-1) - d. In binary this is the 1's complement (flip every bit); in decimal it is the 9's complement.
  • The radix complement (r's complement) is rn−Nr^n - N for N≠0N \ne 0 and 0 for N=0N = 0. It equals the (r-1)'s complement plus 1. In binary this is the 2's complement; in decimal, the 10's complement.

Examples: the 9's complement of 546700546700 is 453299453299 and its 10's complement is 453300453300. The 1's complement of 10110001011000 is 01001110100111 and its 2's complement is 01010000101000.

Subtraction by complement addition. To compute M−NM-N with nn radix-rr digits, first return MM if N=0N=0. Otherwise add MM to the r's complement of NN, retaining the end carry. An end carry means a nonnegative result, including zero when M=NM=N; discard only that final carry.

  • If the sum produces an end carry out of the top digit, discard it: the remaining digits are M−N≥0M - N \ge 0.
  • If there is no end carry, the result is negative: M−N=−(r’s complement of the sum)M - N = -(\text{r's complement of the sum}).

Decimal, 5 digits: 61428−0237561428 - 02375. The 10's complement of 0237502375 is 9762597625, and 61428+97625=15905361428 + 97625 = 159053. Discard the carry: 5905359053. Reversed, 02375−6142802375 - 61428: 02375+38572=4094702375 + 38572 = 40947, no end carry, so the answer is −(10’s complement of 40947)=−59053-(10\text{'s complement of } 40947) = -59053.

The same rule in binary with the 2's complement is the basis of every hardware subtractor (see Signed Number Representation). With the (r-1)'s complement instead, an end carry is not discarded but added back to the least significant digit (end-around carry).

Algorithms and pseudocode

Pseudocode uses integer division div and remainder mod, and writes digits into an array from the least significant position.

Text
DEC-TO-RADIX(N, r)                    // N >= 0, r >= 2
1  if N = 0 then return "0"
2  digits <- empty list
3  while N > 0
4      append (N mod r) to digits
5      N <- N div r
6  reverse digits
7  return digits as a string in the alphabet of radix r

FRAC-DEC-TO-BIN(f, maxbits)           // 0 <= f < 1
1  bits <- empty list
2  for i <- 1 to maxbits
3      f <- 2 * f
4      if f >= 1 then
5          append 1 to bits; f <- f - 1
6      else
7          append 0 to bits
8      if f = 0 then break
9  return bits
  • DEC-TO-RADIX: best, average and worst case are the same, one division per output digit, so ⌊log⁡rN⌋+1\lfloor \log_r N \rfloor + 1 divisions for N≥1N \ge 1, which is Θ(1+log⁡rN)\Theta(1+\log_r N). For N=255N = 255: 8 divisions in radix 2, 2 in radix 16.
  • FRAC-DEC-TO-BIN, best case: 1 iteration, for f=0f = 0 or f=1/2f = 1/2.
  • FRAC-DEC-TO-BIN with integer maxbits≥1\textit{maxbits}\ge1: zero takes one iteration; a nonzero reduced fraction p/2kp/2^k takes exactly min⁡(k,maxbits)\min(k,\textit{maxbits}) iterations. For 0.625=5/80.625=5/8 and a cap at least 3, this is 3. If a zero cap is allowed, the loop performs zero iterations and emits no fractional digits.
  • FRAC-DEC-TO-BIN, worst case: maxbits\textit{maxbits} iterations, reached by every ff whose reduced denominator has an odd prime factor, such as 0.10.1; these never reach exact zero. An average requires a distribution on ff; none is assumed here.

Cost and storage model. Count unit-cost exact-register arithmetic, comparisons and amortised constant-time output append; these are digit/iteration counts, not arbitrary-precision bit costs. Let d=1d=1 for N=0N=0, otherwise d=⌊log⁡rN⌋+1d=\lfloor\log_r N\rfloor+1. DEC-TO-RADIX takes Θ(d)\Theta(d) operations in every case at a fixed digit length, including in-place reversal, and uses Θ(d)\Theta(d) output-materialization storage plus O(1)O(1) registers beyond those buffers. If converting the digit list allocates a separate final string, the temporary list itself is Θ(d)\Theta(d) auxiliary storage when only the returned string is excluded; constant workspace is claimed only when the digit buffer is also excluded or reused as output. For FRAC-DEC-TO-BIN let tt be the actual iterations with a nonnegative integer cap. Time is Θ(t+1)\Theta(t+1) and output storage Θ(t+1)\Theta(t+1) including the empty-list header, with O(1)O(1) working registers excluding that returned list and the input. These storage bounds apply in best, average and worst cases through their respective output lengths; exact-register counts do not imply constant bit storage for unbounded numbers.

Mathematical explanation

Uniqueness. For integer radix r≥2r \ge 2, every non-negative integer has a unique finite representation with no leading zeros (the single digit 0 represents zero). Fractions need not terminate; a terminating expansion in one radix need not terminate in another.

Digit count. The number of digits of N≥1N \ge 1 in radix rr is ⌊log⁡rN⌋+1=⌈log⁡r(N+1)⌉\lfloor \log_r N \rfloor + 1 = \lceil \log_r (N+1) \rceil for the usual floor form, equivalently one more than the exponent of the highest power of rr not exceeding NN.

Bit width for a range. To store every integer in {0,1,…,M}\{0, 1, \ldots, M\} you need ⌈lg⁡(M+1)⌉\lceil \lg (M+1) \rceil bits. To store NN distinct codes you need ⌈lg⁡N⌉\lceil \lg N \rceil bits.

Unknown-radix equations. Expand every numeral as a polynomial in the unknown radix, solve, and keep only integer roots that exceed the largest digit present. Three outcomes occur and all three are examinable:

  • Exactly one radix. (224)r=(13)r\sqrt{(224)_r} = (13)_r means 2r2+2r+4=(r+3)2=r2+6r+92r^2 + 2r + 4 = (r + 3)^2 = r^2 + 6r + 9, so r2−4r−5=(r−5)(r+1)=0r^2 - 4r - 5 = (r - 5)(r + 1) = 0. Reject r=−1r = -1; r=5r = 5 exceeds the largest digit 4, so r=5r = 5. Check: (224)5=64(224)_5 = 64 and (13)5=8(13)_5 = 8.
  • Every radix. (121)r=(11)r2(121)_r = (11)_r^2 because r2+2r+1=(r+1)2r^2 + 2r + 1 = (r+1)^2 is an identity. It holds for every legal radix, r≥3r \ge 3, so a question asking "how many radices" has the answer "infinitely many".
  • No radix. (35)r=2710(35)_r = 27_{10} gives 3r+5=273r + 5 = 27, r=22/3r = 22/3, not an integer: no radix works.

When does a fraction terminate? Write the fraction in lowest terms p/qp/q. Its radix-rr expansion terminates if and only if every prime factor of qq divides rr. Proof sketch: a terminating expansion with kk digits is m/rkm / r^k, which forces q∣rkq \mid r^k; conversely if every prime of qq divides rr, then q∣rkq \mid r^k for large enough kk and p/q=(p rk/q)/rkp/q = (p\,r^k/q)/r^k.

  • 0.1=1/100.1 = 1/10 has the prime 5 in its denominator, so it does not terminate in binary. Its expansion is 0.00011‾20.0\overline{0011}_2: one 0 and then the block 0011 repeating with period 4.
  • 1/31/3 does not terminate in binary or decimal (0.01‾20.\overline{01}_2), but it is (0.1)3(0.1)_3 in base 3.
  • Every finite binary fraction terminates in decimal because 2∣102\mid10. A representation with kk bits after the point needs at most kk decimal places; exactly kk when it is the shortest terminating binary representation. For example, 2−3=0.1252^{-3}=0.125, but 0.1002=0.50.100_2=0.5.

Digit count of large powers. 21002^{100} has ⌊100log⁡102⌋+1=31\lfloor 100 \log_{10} 2 \rfloor + 1 = 31 decimal digits, but in hex it is a 1 followed by 25 zeros (since 2100=16252^{100} = 16^{25}), so it has 26 hex digits. In octal, 2100=2⋅8332^{100} = 2 \cdot 8^{33}, which is 34 octal digits.

Worked examples

Example 1: mixed conversions of 156

  • Binary: 10011100210011100_2 (from repeated division above).
  • Octal: group 010 011 100→2348010\,011\,100 \to 234_8.
  • Hex: group 1001 1100→9C161001\,1100 \to 9\text{C}_{16}.
  • Check: 9⋅16+12=144+12=1569\cdot 16 + 12 = 144 + 12 = 156.

Example 2: hex word to decimal and binary

(BEEF)16=11⋅163+14⋅162+14⋅16+15=4887910(\text{BEEF})_{16} = 11\cdot 16^3 + 14\cdot 16^2 + 14\cdot 16 + 15 = 48879_{10}. Expanding digits: B =1011= 1011, E =1110= 1110, E =1110= 1110, F =1111= 1111, so BEEF16=1011 1110 1110 11112\text{BEEF}_{16} = 1011\,1110\,1110\,1111_2.

Example 3: octal and binary literals in questions

(475)8=4⋅64+7⋅8+5=31710(475)_8 = 4\cdot 64 + 7\cdot 8 + 5 = 317_{10}. Binary grouping of 4758475_8: 100 111 1012100\,111\,101_2.

Example 4: how many bits for 1000 values

⌈lg⁡1000⌉=10\lceil \lg 1000 \rceil = 10. With 10 bits the range is 0..10230..1023, which covers 1000 values; 9 bits cover only 512 values.

Example 5: binary fraction of one tenth

Repeated multiplication of 0.10.1 by 2 for eight steps yields bits 0,0,0,1,1,0,0,10,0,0,1,1,0,0,1. Truncating to eight fractional bits stores 0.000110012=25/256=0.09765625100.00011001_2 = 25/256 = 0.09765625_{10}, an absolute error of about 0.002340.00234.

Example 6: counting ones in a weighted sum

How many 1 bits does the binary form of 3⋅4096+15⋅256+5⋅16+33 \cdot 4096 + 15 \cdot 256 + 5 \cdot 16 + 3 have? Because 4096=1634096 = 16^3, 256=162256 = 16^2 and 16=16116 = 16^1, the coefficients are hex digits: the number is (3F53)16=0011 1111 0101 00112(3\text{F}53)_{16} = 0011\,1111\,0101\,0011_2. Count per digit: 2+4+2+2=102 + 4 + 2 + 2 = 10 ones. The value is 162111016211_{10}, but no decimal conversion is needed. Imperative rule. When a sum is written in powers of 8 or 16, read it directly as octal or hex digits, provided each coefficient is a legal digit.

Example 7: an unknown base from a sum

Find bb with (123)b=3810(123)_b = 38_{10}. Then b2+2b+3=38b^2 + 2b + 3 = 38, b2+2b−35=(b+7)(b−5)=0b^2 + 2b - 35 = (b + 7)(b - 5) = 0, so b=5b = 5, which exceeds the largest digit 3. A second check: in base 5, (123)5=25+10+3=38(123)_5 = 25 + 10 + 3 = 38.

Important properties and observations

  • Grouping works when both radices are powers of a common base, r=car = c^a and s=cbs = c^b: binary, octal and hex are all powers of 2, and base 3 and base 9 are powers of 3. Octal to hex can go through binary, or directly by mapping 4 octal digits to 3 hex digits because 84=1638^4 = 16^3. 10 and 16 are not powers of a common base, so decimal to hex needs a true conversion.
  • Leading zeros do not change an integer's value; trailing zeros after a binary point do change a fraction's apparent precision but not its value if they are truly zero.
  • 210=1024≈1032^{10} = 1024 \approx 10^3, so 210k≈103k2^{10k} \approx 10^{3k}. This approximates byte and word sizes in memory questions.
  • MSB and LSB: the leftmost bit of an integer bit string is the most significant; the rightmost is the least significant. Endianness matters only when the discussion is about memory byte order (that is a Computer Organization concern).

Common misconceptions.

  • "Octal digits go up to 8." Digits run 0..70..7; a written 8 is illegal in octal.
  • "Hex F is 16." F is 15; the radix itself never appears as a digit.
  • "Any fraction that terminates in decimal terminates in binary." False: 0.1100.1_{10} does not.
  • "The answer rr of an unknown-radix equation is any positive root." It must also be an integer greater than every digit in the equation.
  • "The 1's complement and the 2's complement differ by one in every case." True for nonzero NN; for N=0N = 0 the 2's complement is 0 (the carry out of the top is dropped), while the 1's complement is all ones.

GATE examination perspective

  • RADIX CONVERSION TRACES. Expect a small table of quotients and remainders, or a request for one specific digit (for example the third remainder).
  • GROUPING TRAPS. Misaligned groups (starting from the wrong end) flip the answer. Always group from the radix point.
  • BIT-WIDTH QUESTIONS. Distinguish "values from 0 to NN" (⌈lg⁡(N+1)⌉\lceil\lg (N+1)\rceil bits) from "NN distinct codes" (⌈lg⁡N⌉\lceil\lg N\rceil bits).
  • FRACTION QUESTIONS. Ask for the first kk bits, or for the exact terminating expansion when it exists (0.6250.625, 0.3750.375, 0.1250.125).
  • ILLEGAL DIGITS. A string containing digit rr or higher is not a valid radix-rr numeral.
  • UNKNOWN RADIX. Solve the polynomial, then filter: integer, and larger than the largest digit. Watch for identities (every radix works) and for non-integer roots (none works).
  • POWER-OF-RADIX SUMS. A sum of multiples of 16k16^k or 8k8^k is a hex or octal numeral in disguise; count bits per digit.
  • COMPLEMENT SUBTRACTION. If N=0N=0, return MM. Otherwise an end carry means a nonnegative result (zero for equality); discard that final carry. Without it, take the negative of the complement of the sum.
  • TERMINATION. A fraction terminates in radix rr exactly when its reduced denominator has no prime factor outside rr.

Summary

Sources

  1. M. Morris Mano, M. D. Ciletti, Digital Design, 5th ed., Pearson, 2013: Chapter 1, Sections 1.2 to 1.4 (binary numbers, number-base conversions, octal and hexadecimal).
  2. Official GATE 2027 Computer Science and Information Technology syllabus (organising institute IIT Madras), Section 2 "Digital Logic": "Number representation and arithmetic (fixed and floating point)", (consulted 2026-11-11).

Next steps