TOPICS
Search

Binary


The base 2 method of counting in which only the digits 0 and 1 are used. In this base, the number 1011 equals 1·2^0+1·2^1+0·2^2+1·2^3=11. 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 digits are called a crumb, four digits are called a nibble, and eight digits are called a byte.

An integer n may be represented in binary in the Wolfram Language using the command BaseForm[n, 2], and the first d digits of a real number x may be obtained in binary using RealDigits[x, 2, d]. Finally, a list of binary digits l can be converted to a decimal rational number or integer using FromDigits[l, 2].

Binary

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.

111110112110101
2101211002210110
3111311012310111
41001411102411000
51011511112511001
611016100002611010
711117100012711011
8100018100102811100
9100119100112911101
10101020101003011110

A negative number -n is most commonly represented in binary using the complement of the positive number n-1, so -11=00001011_2 would be written as the complement of 10=00001010_2, or 11110101. This allows addition to be carried out with the usual carrying and the leftmost digit discarded, so 17-11=6 gives

 00010001   17 
11110101__  -11__ 
00000110   6.

The number of times k that a given binary number b_n...b_2b_1b_0 is divisible by 2 is given by the position of the first b_k=1 counting from the right. For example, 12=1100 is divisible by 2 twice, and 13=1101 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 binary notation by interpreting digits past the "decimal" point as negative powers of two, so the binary digits ...b_2b_1b_0.b_(-1)b_(-2)... would represent the number

 ...+b_2·2^2+b_1·2^1+b_0·2^0+b_(-1)·2^(-1)+b_(-2)·2^(-2)+....

Therefore, 1/2 would be represented as 0.1_2, 1/4 as 0.01_2, 3/4 as 0.11_2, and so on. The sequence of binary digits for the integers n=0, 1, ... concatenated together and interpreted as a binary constant give the binary Champernowne constant C=0.11011100..._2 (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) reals!

Binary multiplication of single bit numbers (0 or 1) is equivalent to the AND operation, as can be seen in the following multiplication table.

×01
000
101
BinarySums

Consider the cumulative digit sum of all binary numbers up to 1, 2, ..., n. The first few terms are then 1, 2, 4, 5, 7, 9, 12, 13, 15, 17, 20, 22, ... (OEIS A000788). This sequence in monotonic 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.


See also

Base, Binary Carry Sequence, Bit, Blancmange Function, Byte, Champernowne Constant, Crumb, Decimal, Digit Count, Eye of Horus Fraction, Factorial, Hexadecimal, Moser-de Bruijn Sequence, Negabinary, Nibble, Octal, Quaternary, Rudin-Shapiro Sequence, Russian Multiplication, Stolarsky-Harborth Constant, Ternary Explore this topic in the MathWorld classroom

Explore with Wolfram|Alpha

References

Graham, R. L.; Knuth, D. E.; and Patashnik, O. "Factorial Factors." §4.4 in Concrete Mathematics: A Foundation for Computer Science, 2nd ed. Reading, MA: Addison-Wesley, pp. 111-115, 1994.Heath, F. G. "Origin of the Binary Code." Sci. Amer. 227, 76-83, Aug. 1972.Lauwerier, H. Fractals: Endlessly Repeated Geometric Figures. Princeton, NJ: Princeton University Press, pp. 6-9, 1991.Pappas, T. "Computers, Counting, & Electricity." The Joy of Mathematics. San Carlos, CA: Wide World Publ./Tetra, pp. 24-25, 1989.Press, W. H.; Flannery, B. P.; Teukolsky, S. A.; and Vetterling, W. T. "Error, Accuracy, and Stability" and "Diagnosing Machine Parameters." §1.2 and §20.1 in Numerical Recipes in FORTRAN: The Art of Scientific Computing, 2nd ed. Cambridge, England: Cambridge University Press, pp. 18-21, 276, and 881-886, 1992.Sloane, N. J. A. Sequences A000788/M0964, A007814, and A030190 in "The On-Line Encyclopedia of Integer Sequences."Trott, M. The Mathematica GuideBook for Programming. New York: Springer-Verlag, 2004. http://www.mathematicaguidebooks.org/.Wells, D. The Penguin Dictionary of Curious and Interesting Numbers. Middlesex, England: Penguin Books, pp. 42-44, 1986.Wolfram, S. A New Kind of Science. Champaign, IL: Wolfram Media, p. 117, 2002.

Referenced on Wolfram|Alpha

Binary

Cite this as:

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

Subject classifications