Introduction
A number system of radix (base) represents each value as a weighted sum of powers of , with digit symbols drawn from . 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 -digit integer in radix
has decimal value
A fractional part contributes .
| Radix | Name | Digit alphabet | Typical use |
|---|---|---|---|
| 2 | Binary | 0, 1 | Hardware, memory, buses |
| 8 | Octal | 0 to 7 | Compact groups of 3 bits |
| 10 | Decimal | 0 to 9 | Human I/O |
| 16 | Hexadecimal | 0 to 9, A to F | Compact groups of 4 bits |
Hexadecimal digits. A , B , C , D , E , F . Case does not matter for the value.
Valid-digit rule. A numeral is legal in radix only if every digit is less than . So the smallest radix in which a numeral can be read is : needs , and a numeral containing the digit 9 can never be octal. Every unknown-radix question starts by writing down this lower bound.
Range of digits in radix . The -digit numerals in radix are exactly to , so there are of them. If leading zeros are forbidden, there are numerals with exactly digits; for example, three-digit numerals in base 7.
Why powers of two matter
Because and , 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:
| 0 | 1 | 8 | 256 |
|---|---|---|---|
| 1 | 2 | 9 | 512 |
| 2 | 4 | 10 | 1024 |
| 3 | 8 | 12 | 4096 |
| 4 | 16 | 16 | 65536 |
| 5 | 32 | 20 | about |
| 6 | 64 | 30 | about |
| 7 | 128 | 32 | about |
Range of an unsigned -bit word
With bits you can represent exactly distinct patterns, namely the integers . To represent distinct values you need at least bits. For , because .
How it works
Integer: radix to decimal
Expand by powers. Example: . Same method for any radix.
Integer: decimal to radix (repeated division)
Repeatedly divide by and record remainders. They are generated least significant first; read bottom to top to obtain digits most significant to least significant.
Example. Convert to binary:
| Division | Quotient | Remainder |
|---|---|---|
| 78 | 0 | |
| 39 | 0 | |
| 19 | 1 | |
| 9 | 1 | |
| 4 | 1 | |
| 2 | 0 | |
| 1 | 0 | |
| 0 | 1 |
Reading remainders bottom to top: . The same procedure with divisor 8 gives ; with divisor 16 gives .

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. .
- Binary to hex: group in fours. .
- 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: and .
- Mixed example: and . Both equal .
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, , group radix- digits per radix- 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 (), group through that base, or map 4 octal digits directly to 3 hex digits. Otherwise go through decimal.
Example. to base 9: since , group pairs from the right: . Then and , so . Check: and .
Example. to hex: octal digits to bits , regroup in fours from the right , so .
Example. to hex by mapping 4 octal digits to 3 hex digits, because : .
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. : (bit 1), (bit 0), (bit 1). So .
Recurring fractions. Many finite decimals are infinite in binary. The fraction yields the repeating bit string . The first eight bits after the point are . 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: .
Arithmetic in radix
Addition works column by column as in decimal: when a column sum reaches or more, write and carry 1 (a column sum can never exceed , so the carry is at most 1).
- Hex: . Column 0: , write 3, carry 1. Column 1: , write 0, carry 1. Result . Check: .
- Octal: . Columns give , then , then . Result . Check: .
Radix complements
For an -digit number in radix :
- The diminished radix complement ((r-1)'s complement) is . It is formed digit by digit: replace each digit by . 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 for and 0 for . 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 is and its 10's complement is . The 1's complement of is and its 2's complement is .
Subtraction by complement addition. To compute with radix- digits, first return if . Otherwise add to the r's complement of , retaining the end carry. An end carry means a nonnegative result, including zero when ; discard only that final carry.
- If the sum produces an end carry out of the top digit, discard it: the remaining digits are .
- If there is no end carry, the result is negative: .
Decimal, 5 digits: . The 10's complement of is , and . Discard the carry: . Reversed, : , no end carry, so the answer is .
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.
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 divisions for , which is . For : 8 divisions in radix 2, 2 in radix 16.
- FRAC-DEC-TO-BIN, best case: 1 iteration, for or .
- FRAC-DEC-TO-BIN with integer : zero takes one iteration; a nonzero reduced fraction takes exactly iterations. For 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: iterations, reached by every whose reduced denominator has an odd prime factor, such as ; these never reach exact zero. An average requires a distribution on ; 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 for , otherwise . DEC-TO-RADIX takes operations in every case at a fixed digit length, including in-place reversal, and uses output-materialization storage plus registers beyond those buffers. If converting the digit list allocates a separate final string, the temporary list itself is 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 be the actual iterations with a nonnegative integer cap. Time is and output storage including the empty-list header, with 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 , 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 in radix is for the usual floor form, equivalently one more than the exponent of the highest power of not exceeding .
Bit width for a range. To store every integer in you need bits. To store distinct codes you need 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. means , so . Reject ; exceeds the largest digit 4, so . Check: and .
- Every radix. because is an identity. It holds for every legal radix, , so a question asking "how many radices" has the answer "infinitely many".
- No radix. gives , , not an integer: no radix works.
When does a fraction terminate? Write the fraction in lowest terms . Its radix- expansion terminates if and only if every prime factor of divides . Proof sketch: a terminating expansion with digits is , which forces ; conversely if every prime of divides , then for large enough and .
- has the prime 5 in its denominator, so it does not terminate in binary. Its expansion is : one 0 and then the block 0011 repeating with period 4.
- does not terminate in binary or decimal (), but it is in base 3.
- Every finite binary fraction terminates in decimal because . A representation with bits after the point needs at most decimal places; exactly when it is the shortest terminating binary representation. For example, , but .
Digit count of large powers. has decimal digits, but in hex it is a 1 followed by 25 zeros (since ), so it has 26 hex digits. In octal, , which is 34 octal digits.
Worked examples
Example 1: mixed conversions of 156
- Binary: (from repeated division above).
- Octal: group .
- Hex: group .
- Check: .
Example 2: hex word to decimal and binary
. Expanding digits: B , E , E , F , so .
Example 3: octal and binary literals in questions
. Binary grouping of : .
Example 4: how many bits for 1000 values
. With 10 bits the range is , which covers 1000 values; 9 bits cover only 512 values.
Example 5: binary fraction of one tenth
Repeated multiplication of by 2 for eight steps yields bits . Truncating to eight fractional bits stores , an absolute error of about .
Example 6: counting ones in a weighted sum
How many 1 bits does the binary form of have? Because , and , the coefficients are hex digits: the number is . Count per digit: ones. The value is , 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 with . Then , , so , which exceeds the largest digit 3. A second check: in base 5, .
Important properties and observations
- Grouping works when both radices are powers of a common base, and : 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 . 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.
- , so . 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 ; 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: does not.
- "The answer 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 ; for 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 " ( bits) from " distinct codes" ( bits).
- FRACTION QUESTIONS. Ask for the first bits, or for the exact terminating expansion when it exists (, , ).
- ILLEGAL DIGITS. A string containing digit or higher is not a valid radix- 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 or is a hex or octal numeral in disguise; count bits per digit.
- COMPLEMENT SUBTRACTION. If , return . 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 exactly when its reduced denominator has no prime factor outside .
Summary
Sources
- 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).
- 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).