KEVOS
ArticlesServicesCase studiesAboutContact
ArticlesServicesCase studiesAboutContact
← ArticlesRepresenting Large IntegersEngineering · Engineering MathematicsLesson 547/884← PrevNext →
ArticlePublished 7 Aug 20263 min readBy Kevin Jogin
On this page

Ask about this page

KEVOS AIRepresenting Large Integers

KEVOS knowledge first · trusted web sources when needed

Engineering  /  Mathematics  — Integer Algorithms

Representing Large Integers

Positional representation of multiprecision integers, base selection, sign handling and normalisation invariants.

Page KV-MATH-0319Reading time 3 minReviewed 2026-08-07Author Kevin Jogin

Executive summary

A multiprecision integer is an array of digits in a base chosen to match the machine word, together with a sign and a length. Every arithmetic routine depends on invariants of this representation being maintained.

The choices — base, digit order, sign convention, normalisation — are implementation decisions with measurable consequences and no single correct answer.

Learning objectives

  1. Describe positional representation and prove uniqueness.
  2. Select a base appropriate to a machine architecture.
  3. State the invariants an implementation must maintain.

01Positional representation

Theorem

Base representation

For any base B ≥ 2, every non-negative integer a has a unique representation

a = Σ aᵢ B^i with 0 ≤ aᵢ < B and leading digit non-zero.

Existence and uniqueness both follow from repeated division with remainder. The number of digits is ⌊log_B a⌋ + 1, so the length in bits is roughly log₂ a regardless of base — the base affects constants and implementation, not asymptotic size.

len_B(a) = ⌊log_B a⌋ + 1    for a ≥ 1,   len_B(0) = 1 by convention

02Choosing the base

The base is chosen so that a digit fits a machine word and the product of two digits fits the widest available accumulator.

Base selection
ArchitectureTypical baseProduct fits
32-bit, 64-bit accumulator2³²64-bit product register
64-bit, 128-bit accumulator2⁶⁴128-bit product via compiler intrinsic
Portable C, no wide type2³² with 32-bit digitsSplit multiplication into halves
Decimal output required10⁹Simplifies printing at arithmetic cost
Note
Using a power-of-two base makes division by the base a shift and reduction modulo the base a mask, both free. A decimal base makes conversion for display trivial but every arithmetic operation slightly slower. Libraries almost always choose the power of two and pay the conversion cost only on output.

03Invariants and sign

Sign-magnitude representation — an unsigned digit array plus a separate sign flag — is standard, in contrast to the two's complement used for fixed-width machine integers. It simplifies multiplication and division at the cost of a branch in addition.

  • No leading zeros. The most significant digit is non-zero, except for the value zero itself. Without this, equality comparison and length queries become unreliable.
  • Canonical zero. Zero has length one and a positive sign flag, so that no negative zero exists.
  • Digits in range. Every digit satisfies 0 ≤ aᵢ < B after every operation; carries must be fully propagated before a routine returns.
  • Length matches capacity. The stored length reflects the significant digits, not the allocated buffer.
Caution
Failing to strip leading zeros after a subtraction is the classic multiprecision bug. The value is still correct but comparisons, length-dependent branches and division loops all misbehave, and the symptom appears far from the cause.

04Frequently asked questions

Little-endian or big-endian digit order?

Little-endian — least significant digit first — is nearly universal in libraries, because it makes growing a number an append rather than a shift, and index i corresponds to the coefficient of B^i without an offset computation.

Why not use two's complement for multiprecision?

Because it requires a fixed width to define the sign bit position, and multiprecision numbers have no fixed width. Sign-magnitude keeps the magnitude a plain unsigned array whose length can change freely.

Does the base choice affect asymptotic complexity?

No. Changing base multiplies the digit count by a constant factor, which asymptotic notation absorbs. It affects the constant, which for a heavily used library is worth optimising carefully.

Related pages

  • Machine Models and Complexity Theory
  • Integer Addition and Subtraction

Sources and method

Structural reference: Victor Shoup, A Computational Introduction to Number Theory and Algebra, Version 1, Cambridge University Press, 2005 — book pages 39-41.

This page carries the durable method layer only: definitions, constructions, algorithms, complexity results and selection criteria, authored originally for KEVOS. No text is transcribed or paraphrased from the source, and no numeric tables or benchmark data are reproduced — these are routed to live authoritative sources instead.

Author: Kevin Jogin. Last reviewed 2026-08-07.

Continue learning

Machine Models and Complexity TheoryArticle · Engineering MathematicsNEXT LESSON →Integer Addition and SubtractionArticle · Engineering MathematicsAsymptotic Notation for Algorithm AnalysisArticle · Engineering MathematicsInteger MultiplicationArticle · Engineering Mathematics
KEVOS · Engineering, manufacturing and project improvement
ArticlesServicesCase studiesAboutContact
© 2026 KEVOS®