Binary numeral system Created 2026-09-29 Updated 2026-10-14
The binary numeral system is positional notation with radix two. Each binary digit is zero or one, and its place value is a power of two. A one includes that weight in the sum; a zero skips it. The binary representation therefore selects and represents the integer .
To obtain those binary digits from , repeatedly use Euclidean division by two:
The remainders, in the order produced, are . Read them in reverse order to get . The final zero is the quotient that stops the conversion, not an additional leading binary digit. Starting with zero itself needs the special single-digit representation .
A useful independent check reads the binary digits from left to right. Start with and, for each binary digit , replace by . For , the intermediate values are . This reconstructs the integer without reversing a list and explains why appending a zero on the right doubles the value.
Binary is well suited to computation because each binary digit has just two possibilities. A stored bit can encode either possibility; groups of bits encode larger integers. Practical integer arithmetic can use a radix that is itself a power of two, grouping several binary digits into each stored numeral digit.[ref] A displayed negative integer, such as , uses a separate sign. A computer's particular signed storage convention is an additional encoding choice, so the displayed sign should not be confused with an extra binary place.
The binary powering multiplication count counts arithmetic operations. The time complexity measured in operations on individual bits also depends on operand lengths. Put , the binary length of the modulus, and let be the positive exponent's binary length. Stored residues use at most bits, and an unreduced product uses at most bits.
With ordinary long multiplication and division with remainder, one modular product costs operations on bits. Combining that cost with modular products gives
This bound includes reductions in the loop, and assumes the base has already been reduced and the exponent is available as a binary expansion. Reading the exponent takes additional work; initial reduction of a very long base depends on its input length, and an inverse for a negative exponent adds further work. More generally, if a modular product costs operations on bits, the powering loop costs . Faster multiplication and reduction methods can improve the quadratic bound.[ref]
For ordinary integer powers with , the output itself has binary digits. Even writing it takes work proportional to that length. Consequently multiplications does not imply operations on bits: the operands grow during ordinary exponentiation by squaring, whereas modular exponentiation keeps them bounded by the modulus. A squaring or multiplication by a small fixed base can also cost less than a general product, so equal counts need not mean equal running times.
Carmichael function Created 2026-09-24 Updated 2026-10-13
For an integer , the Carmichael function is the exponent of a finite group for the unit group : the least positive integer for which
Here the greatest common divisor condition selects the units. Euler's totient function counts them; the Carmichael function gives their least common return exponent.[ref]
Modulo eight, the units are , and their squares are all congruent to one. Their multiplicative orders are , so although . Modulo fifteen, the units have multiplicative orders . For example, the powers of two return through . Thus although ; the multiplicative order of four is only two.
Figure 1.
Individual unit orders divide the least common return exponent modulo eight and fifteen
. Details.
The three quantities are related by
A common return exponent must be a multiple of every multiplicative order, hence of their least common multiple. Conversely, that least common multiple makes every unit return to one. Lagrange's theorem makes each multiplicative order divide the group order , proving the final divisibility. The Carmichael function applies to all units at once, while the multiplicative order concerns a chosen unit.
For the prime factorization with distinct prime numbers and , the formulas are
These are least common multiples, rather than products: . The convention handles the trivial case separately.[ref]
The Chinese remainder theorem for unit groups explains the least common multiple: a power returns to one in every prime power component exactly when it is a multiple of each component's exponent of a finite group. For an odd prime power, the unit group is a cyclic group of group order . For , the unit group modulo is a direct product of groups , generated by the classes of and five, so its exponent of a finite group is .[ref]
This gives a uniform reduction for modular exponentiation: for a unit and a nonnegative integer , reduce modulo . For example, because . The unit hypothesis matters: , but . Computing the formula assumes the prime factorization is available. The same common-exponent viewpoint explains Carmichael numbers: a composite number passes the Fermat primality test for every unit base exactly when . For example, .
Exponentiation by squaring Created 2026-10-03 Updated 2026-10-14
Exponentiation by squaring computes an integer power by reading the exponent's binary expansion. Appending a binary digit to a prefix of value replaces by , so the corresponding power changes by
Each new digit requires one squaring and, only for digit one, one further multiplication. The number of digits grows with the logarithm of the exponent, making this useful for modular exponentiation, primality testing, and powers of matrices using matrix multiplication.[ref]
For a concrete calculation, , so . The optimized left-to-right algorithm used here instead keeps one accumulated power: initialize from the leading digit one, then process only the remaining digits :
Thus , using three squarings and two further multiplications, instead of twelve successive multiplications starting at .
Figure 1.
Reading the same binary expansion computes and
. Each appended binary digit changes the prefix value by . The ordinary-power row grows to ; the modular exponentiation row stores only remainders . Both traces use three squarings and two further multiplications. Details.
For a general positive integer with leading digit , set and, for , first replace by , then multiply it by if . Return . This explicitly skips the leading digit's otherwise unnecessary operations on one. A Computational Introduction to Number Theory and Algebra by Victor Shoup (Section 3.4, pp. 65–66) presents the version initialized at one and processing every digit; the optimization here makes the counting convention unambiguous.
The loop invariant is , where is the value of the digits already read. Initially and . If the next digit is , then squaring and optionally multiplying give , exactly the next prefix. At termination . This proof uses associativity of multiplication; it works in any monoid, including matrices with the identity matrix as identity element, and needs no commutativity between different bases.
For , return the identity element without performing a multiplication. This is the empty-product convention ; if , the algorithm therefore returns one for by convention, rather than resolving its meaning in every mathematical setting. Negative integer exponents require an inverse element: compute , counting the inversion separately. Over the integers, such an inverse generally leaves the integers, and a zero base has no inverse.
Integer Created 2026-09-24 Updated 2026-10-14
An integer is a whole number, positive, negative, or zero. The set of all integers is
The positive integers are ; the negative integers are their opposites . Zero is neither positive nor negative. The nonnegative integers include zero and all the positive integers. On a number line, consecutive integers are one unit apart, negative integers lie to the left of zero, and positive integers lie to its right. [ref]
The integers let counting describe changes in both directions. If a counter starts at and increases by five, it reaches : . Decreasing that result by four gives . In addition on the number line, the sign of the added integer chooses the direction and its absolute value gives the distance. The additive inverse reverses the change made by .
Figure 1. . Starting at , a change of ends at . A subsequent change of ends at . The arrows indicate changes; the labelled points indicate integers. Zero separates the negative and positive sides. Details.
The integers have closure under a binary operation for addition, subtraction and multiplication: whenever , the results , and are still integers. Together these operations give the integers their ring structure.[ref] For instance, , , and . General division has no such closure: is a rational number but not an integer. Some divisions are exact, such as ; division by zero is undefined. Euclidean division instead produces an integer quotient and a remainder, so retains the information that ordinary division puts into the fraction .
An integer is the value, whereas its written numeral is an encoding. The decimal representation and the binary representation name the same integer. Changing positional notation changes how that value is displayed and how calculations are organized; it does not change the value itself.
Modular exponentiation Created 2026-10-06 Updated 2026-10-14
Modular exponentiation computes the remainder for an integer base , a nonnegative integer exponent , and, here, an integer modulus . It applies exponentiation by squaring while reducing after each multiplication, including each squaring. The result is the unique representative in . There is no requirement that the base be coprime to the modulus when the exponent is nonnegative.[ref]
Take , , and . Initialize ; the remaining digits give
Hence . The final operation multiplies by , since the preceding square has already been reduced. The computation never needs to construct .
In general reduce the base first, . For , initialize and process the remaining binary digits with , followed, for a digit one, by . The loop invariant is
where is the processed prefix value. The congruence is preserved because modular arithmetic respects multiplication: if , then and . Thus changing representatives never changes the final congruence class.
Both factors in every product are less than , so the unreduced product is less than , and the stored result is again less than . The same bounds hold for a gigantic exponent, such as : there are squarings, each on bounded-size residues. For base two, the corresponding ordinary power would have binary digits. The benefit is avoiding the huge ordinary power altogether, rather than constructing it and taking one final remainder. Initial reduction is essential when the supplied base is much larger than the modulus.
For , return under the same empty-product convention as exponentiation by squaring. For , require , find the modular multiplicative inverse , and compute ; the extended Euclidean algorithm can find that inverse. Its cost is separate from the positive-exponent binary powering multiplication count. For example, , while is undefined because and are not coprime.
Multiplicative order Created 2026-09-24 Updated 2026-10-13
For coprime integers with , the multiplicative order is the least positive integer such that
It counts the distinct powers in the cyclic subgroup generated by the congruence class of . Thus it is an order of a group element in the unit group .[ref]
For example, the modular exponentiation , starting at , produces . The first return to one takes three steps, so . Starting at the congruence class three and repeatedly multiplying by two instead gives : these are the other three units modulo seven, outside the cyclic subgroup generated by two.
Figure 1.
Multiplication by two modulo seven has two cycles; its powers follow the cycle through one
. Details.
Euler's theorem guarantees a return to one at exponent , where is Euler's totient function. Thus the multiplicative order exists for every unit.[ref] In fact,
By Lagrange's theorem, the size of the cyclic subgroup divides the size of the unit group, which is Euler's totient function. For two modulo seven, this is ; the multiplicative order need not equal Euler's totient function. If , its multiplicative order is one.
The coprime integers hypothesis is necessary: if , any common divisor of and divides one. For instance, powers of two modulo eight give , with no positive-exponent return to one. This sequence eventually settles, but two has no multiplicative order modulo eight.
Order as the exact period of modular exponentiation Created 2026-09-24 Updated 2026-10-14
Let be coprime integers with , and let be their multiplicative order. For integers ,
Negative exponents mean powers of the modular inverse of . Thus periodic modular exponentiation has smallest positive period , and are distinct congruence classes.[ref]
This lets a huge modular exponentiation reuse a short list: reduce its exponent modulo the multiplicative order, then look up the corresponding power. For example, gives , while gives . When the multiplicative order is unknown, Euler's theorem permits reduction modulo Euler's totient function, though that period may be longer. Repeated squaring remains useful when computing either the unreduced or the reduced power.
For a proof outline, multiply by the modular inverse of , leaving . Apply Euclidean division to write with . Then ; minimality of the multiplicative order forces . The reverse implication follows from . The coprime integers hypothesis enables cancellation: modulo eight, , but this repetition supplies no multiplicative order for two.
Positional notation Created 2026-09-29 Updated 2026-10-14
In positional notation, a numeral digit contributes its value multiplied by a weight determined by its position. Fix an integer radix . A finite string of numeral digits , with , represents the nonnegative integer
The rightmost position has weight ; each move left multiplies the weight by . This weight is the place value. For a nonzero integer, the canonical string has . Zero is written with the single numeral digit . Leading zeros are permitted in a fixed-width display but omitted in the canonical form: . A negative integer is written with a separate minus sign and the positional notation for its absolute value; the minus sign is not a numeral digit.[ref]
For example,
The zero is essential inside this string: , not . It records that the tens position contributes nothing while keeping the hundreds and units in their proper positions. The same integer has binary representation
Figure 1.
One integer, two encodings:
. Each numeral digit is multiplied by its place value. Decimal uses the weights ; binary uses . Zero digits preserve positions without contributing to the total. Both rows sum to . Details.
Repeated Euclidean division constructs the representation exactly. Set . At each step write
Keep the remainder and continue with the integer quotient . A positive quotient strictly decreases, so eventually it is zero. Substituting the successive equations back into the first gives : the numeral digits are obtained from right to left. The remainder modulo uniquely fixes , and then the quotient uniquely fixes the remaining string by the same reasoning. This proves existence and uniqueness once leading zeros are excluded. The needed unique quotient and remainder are precisely the conclusion of the Euclidean division theorem.[ref]
This finite expansion concerns nonnegative integers. Extending positional notation to fractional positions uses weights to the right of a point; an arbitrary real number need not have a finite digit string. In particular, the decimal representation represents , while the base-two string represents . The radix is part of the interpretation.
The benefit is compact arithmetic: positions can encode every nonnegative integer below . To see the upper endpoint, fill all positions with ; the finite geometric series gives . Carrying in addition exchanges units of one place value for one unit of the next. Thus a short string stores a large count and also supplies an algorithm for computing with it.