TOPICS
Search

Binary Expansion


A binary expansion of a nonnegative real number x is a base-2 representation

 (b_m...b_0.b_(-1)b_(-2)...)_2=sum_(k=-infty)^mb_k2^k,

where m is a nonnegative integer and each digit b_k is either 0 or 1. For example, 11=(1011)_2, 5/8=(0.101)_2, and 1/3=(0.01^_)_2.

Negative numbers are not covered by this definition. Their representation requires an additional convention. In ordinary mathematical notation, a minus sign is often placed before a binary numeral. For example, -5=-(101)_2. This is a notation convention, not part of the positional expansion above. In contrast, negabinary, which uses base -2, represents every integer uniquely by a finite string of the digits 0 and 1 and requires no separate sign.

A fixed-width computer representation of a negative integer instead requires an encoding convention. Common choices are sign-and-magnitude representation, ones' complement, and two's complement.

A nonnegative rational number has an eventually periodic binary expansion, and every eventually periodic binary expansion represents a nonnegative rational number. If p/q is a reduced fraction, then its binary expansion terminates iff q is a power of 2.

Every positive real number with a terminating binary expansion also has a nonterminating binary expansion whose digits are eventually all 1s. For example, (0.1000...)_2=(0.0111...)_2. Apart from leading zeros, pairs of this form account for all nonuniqueness of binary expansions.

For n>=1, the Mersenne number M_n=2^n-1 has binary expansion (11...1)_2 with n digits, all equal to 1, and is therefore a binary repunit.

The binary expansion of a number x can be obtained in the Wolfram Language using RealDigits[x, 2].


See also

Base, Binary, Decimal Expansion, Digit, Eventually Periodic, Mersenne Number, Normal Number, Numeral System, Ones' Complement, Radix, Rational Number, Reduced Fraction, Repunit, Sign-and-Magnitude Representation, Two's Complement

Explore with Wolfram|Alpha

References

Knuth, D. E. "Positional Number Systems." §4.1 in The Art of Computer Programming, Vol. 2: Seminumerical Algorithms, 3rd ed. Reading, MA: Addison-Wesley, pp. 195-213, 1998.

Referenced on Wolfram|Alpha

Binary Expansion

Cite this as:

Weisstein, Eric W. "Binary Expansion." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/BinaryExpansion.html

Subject classifications