A binary expansion of a nonnegative real number is a base-2
representation
where
is a nonnegative integer and each digit
is either 0 or 1. For example,
,
, and
.
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,
. This is a notation convention,
not part of the positional expansion above. In contrast, negabinary,
which uses base
, 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
is a reduced fraction, then its binary expansion
terminates iff
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, . Apart from leading zeros,
pairs of this form account for all nonuniqueness of binary expansions.
For ,
the Mersenne number
has binary expansion
with
digits, all equal to 1, and is therefore
a binary repunit.
The binary expansion of a number can be obtained in the Wolfram
Language using RealDigits[x,
2].