Binary is the base-2 numeral system, in which only the binary digits 0 and
1 are used. In this base, the number
1011 equals .
This base is used in computers, since all numbers
can be simply represented as a string of electrically
pulsed ons and offs. In computer parlance, one binary
digit is called a bit, two binary
digits are called a crumb, four binary
digits are called a nibble, and eight binary
digits are called a byte.
An integer may be represented in binary in the Wolfram
Language using the command BaseForm[n,
2], and the first
binary digits of a real number
may be obtained in binary using RealDigits[x,
2, d]. Finally, a list of binary digits
can be converted to a decimal rational number or integer
using FromDigits[l,
2].
The illustration above shows the binary numbers from 0 to 63 represented graphically (Wolfram 2002, p. 117), and the following table gives the binary equivalents of the first few decimal numbers.
| 1 | 1 | 11 | 1011 | 21 | 10101 |
| 2 | 10 | 12 | 1100 | 22 | 10110 |
| 3 | 11 | 13 | 1101 | 23 | 10111 |
| 4 | 100 | 14 | 1110 | 24 | 11000 |
| 5 | 101 | 15 | 1111 | 25 | 11001 |
| 6 | 110 | 16 | 10000 | 26 | 11010 |
| 7 | 111 | 17 | 10001 | 27 | 11011 |
| 8 | 1000 | 18 | 10010 | 28 | 11100 |
| 9 | 1001 | 19 | 10011 | 29 | 11101 |
| 10 | 1010 | 20 | 10100 | 30 | 11110 |
A fixed-width computer representation of a negative integer requires a convention for encoding. Common
choices are sign-and-magnitude representation,
ones' complement, and two's
complement. They differ in the interpretation of the leading bit,
the representation of zero, and the treatment of carries.
These fixed-width encodings are distinct from negabinary,
which uses base to represent every integer without
a separate sign.
The number of times
that a given binary number
is divisible by 2 is given by the position of
the first
counting from the right. For example,
is divisible by 2 twice, and
is divisible by 2 zero times.
The number of times that 1, 2, ... are divisible by 2 are 0, 1, 0, 2, 0, 1, 0, 3,
0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, ... (OEIS A007814),
which is the binary carry sequence.
Real numbers can also be represented using a binary expansion by interpreting binary digits past
the "decimal" point as negative powers of two,
so the binary digits would represent the number
Therefore, 1/2 would be represented as , 1/4 as
, 3/4 as
, and so on. The sequence
of binary digits for the integers
, 1, ... concatenated together and
interpreted as a binary constant give the binary Champernowne
constant
(OEIS A030190).
Unfortunately, the storage of binary numbers in computers is not entirely standardized. Because computers store information in 8-bit bytes (where a bit is a single binary digit), depending on the "word size" of the machine, numbers requiring more than 8 bits must be stored in multiple bytes. The usual FORTRAN77 integer size is 4 bytes long. However, a number represented as (byte1 byte2 byte3 byte4) in a VAX would be read and interpreted as (byte4 byte3 byte2 byte1) on a Sun. The situation is even worse for floating-point (real) numbers, which are represented in binary as a mantissa and characteristic, and worse still for long (8-byte) real numbers!
Binary multiplication of single bit numbers (0 or 1) is equivalent to the AND operation, as can be seen in the following multiplication table.
| 0 | 1 | |
| 0 | 0 | 0 |
| 1 | 0 | 1 |
Consider the cumulative digit sum of all binary numbers up to 1, 2, ..., .
The first few terms are then 1, 2, 4, 5, 7, 9, 12, 13, 15, 17, 20, 22, ... (OEIS
A000788). This sequence
is monotonically increasing (left figure), but if the main asymptotic term is removed,
a sequence of humped curves (right figure; Trott 2004,
p. 218) tending towards the blancmange function
is obtained.