Binary arithmetic is the type of arithmetic that virtually all digital computers use while performing numerical operations (addition, subtraction, multiplication, division, and comparison). The binary number system uses two digits: 0 and 1. All modern digital computers represent data as a collection of such binary digits or bits. A bit is the smallest possible unit of information, and can exist in one of two states: 0 (also labeled "off" or "false") and 1 (also labeled "on" or "true"); a valid bit cannot be halfway between 0 and 1, or both at once. All collections of computer data, such as text files on disks, programs stored in memory, and web pages on the Internet, are ultimately collections of bits.
Since each bit has two possible states (0 and 1), two bits together have four possible states (00, 01, 10, 11), three bits have eight states (000, 001, 010, 011, 100, 101, 110, 111), and so on. The number of possible states of a bit string is given by 2 raised to the power of the string's length: 21 = 2 states, 22 = 4 states, 23 = 8 states, 24 = 16 states, and so on. For example, if a computer display shows 8 colors, then 3 bits can be used to represent this information because 8 colors need 8 distinct labels, which can be supplied by 3 bits. A common grouping of bits is the byte, which is usually composed of 8 bits. An 8-bit byte has 256 different possible states or bit combinations (28 = 256). A byte may symbolize any of 256 distinct entities: these are sometimes taken to be the numbers from 0 to 255. In the most straightforward base 2 notational system (which is often, but not always, used inside computer hardware), the byte 00000000 represents 0 and the byte 11111111 represents 255. Assigning increasing powers of 2 to each bit (starting with 20 = 1 for the rightmost bit) and finding the sum of factors corresponding to nonzero bits converts a binary string in this format into a decimal number between 0 and 255. For example, 216 is represented as 11011000: (0 x 20) + (0 x 21) + (0 x 22) + (1 x 23) + (1 x 24) + (0 x 25) + (0 x 26) + (1 x 27) + (1 x 28) = 0 + 0 + 0 + 8 + 16 + 0 + 64 + 128 = 216.
For ease of use, people usually wish to work with numbers in non-binary form. There are several different non-binary systems in which numbers can be expressed for computer work. The most used systems are the octal (base 8), decimal (base 10), and hexadecimal (base 16) systems. The decimal system is often used to input numbers into computers because it is the system that most people use in everyday life. The computer translates these decimal numbers into binary numbers at the circuit level. It is worth noting that other physical representations of numbers could be constructed: instead of 2-voltage devices to represent the binary digits 1 and 0, 10-voltage devices could be constructed to represent the decimal digits 0-9. However, the latter's greater complexity and increased vulnerability to electronic noise would make them impractical. For simplicity and reliability, binary numbers can't be beat.
Adding
The rules of arithmetic in the binary system are similar to those in the decimal system, the main difference being that the decimal system has ten digits while the binary system has two.
As with decimal numbers, pairs of binary numbers are added digit by digit starting with the rightmost (least significant) digit and working leftwards. In adding bits there only four basic rules: (1) 0 + 0 = 0, (2) 1 + 0 = 1 (same as 0 + 1 = 1), (3) 1 + 1 = 10 (i.e., write 0 in the present digit's place and carry 1 to the next), and (4) 1 + 1 + 1 = 11 (i.e., when a carry has occurred to a place where two 1s are already being added, write 1 in the present digit's place and carry 1 again). For example, to add the two binary numbers 1011 and 1101 (decimal 11 and 13), one calculates as follows (note that the Carry row of Figure 1 shows the "carry over" from digits to the right):
Negative Numbers and Subtraction
In order for the computer to code for negative numbers, these too must be represented as binary strings. One method for doing so is the sign-magnitude system, in which numbers of a certain bit length (i.e., 0100 = decimal 4) are endowed with a single additional bit (the leftmost) to act as a sign bit (i.e., 10100 = decimal -4, where a sign-bit value of 1 means "minus."). However, this technique sacrifices the "pure" form of binary notation; one of the bits does not represent a 1 or a 0, but a completely different sort of symbol (+ or -), and this requires more complex circuitry. Other methods for representing negative numbers in binary form are the one's and two's complement notations. One's complement notation is a used in many computers to represent negative numbers in binary form. To negate a number in the one's-complement system, each bit of the number is inverted (i.e., 0s are replaced with 1s and 1s with 0s). This, wastefully, produces two representations for zero (+0 and -0). Two's complement notation works similarly to one's complement but has only one representation for 0. (As a tradeoff, in two's complement the largest representable negative number has no corresponding positive partner.)
The one's and two's complement notations have the advantage of having identical bit-by-bit rules for both addition and subtraction: that is, one merely adds a negative number to a positive number, bit by bit, as if they were both positive. In the sign-magnitude notation system, however, separate rules are required for subtraction, as follows: (1) 0 - 0 = 0, (2) 1 - 0 = 1, (3) 1 - 1 = 0, and (4) 0 - 1 = 10 (i.e., write 0 in the present digit's place and borrow 1 from the next). For example, to calculate 1101 - 1011 (decimal 13 - 11), one first prefixes a 0 to 1101 to sign that number positive (01101) and a 1 to 1011 to sign that number negative (11011), then calculates as follows:
Multiplication and Division
There are only three bit-by-bit rules to use for the multiplication of binary numbers: (1) 0 x 0 = 0, (2) 0 x 1 = 0 (same as 1 x 0 = 0), and (3) 1 x 1 = 1. For example, to multiply the binary number 1011 by the binary number 0101 (decimal 11 x 5), one calculates as follows:
Binary division is performed in the same fashion as decimal long division but is actually easier because the digits in the quotient can only be 0 or 1. For example to divide binary 1100 by binary 10, (decimal 12 ÷ 2), one calculates as follows:
This is the complete article, containing 1,169 words
(approx. 4 pages at 300 words per page).