# Binary Subtraction Calculator

## What is Binary? And how is it Subtracted?

A binary code represents text, computer processor instructions, or any other data using a two-symbol system. The two-symbol system used is often "0" and "1" from the binary number system. The binary code assigns a pattern of binary digits, also known as bits, to each character, instruction, etc. For example, a binary string of eight bits can represent any of 256 possible values and can, therefore, represent a wide variety of different items. The calculator above helps you add binaries.

In computing and telecommunications, binary codes are used for various methods of encoding data, such as character strings, into bit strings. Those methods may use fixed-width or variable-width strings. In a fixed-width binary code, each letter, digit, or other character is represented by a bit string of the same length; that bit string, interpreted as a binary number, is usually displayed in code tables in octal, decimal or hexadecimal notation. There are many character sets and many character encodings for them.

A bit string, interpreted as a binary number, can be translated into a decimal number. For example, the lower case a, if represented by the bit string 01100001 (as it is in the standard ASCII code), can also be represented as the decimal number "97".

### Representation

Any number can be represented by a sequence of bits (binary digits), which in turn may be represented by any mechanism capable of being in two mutually exclusive states. Any of the following rows of symbols can be interpreted as the binary numeric value of 667:

1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 1 |

| | β | | | β | β | | | | | β | | | | |

β | β | β | β | β | β | β | β | β | β |

y | n | y | n | n | y | y | n | y | y |

The numeric value represented in each case is dependent upon the value assigned to each symbol. In the earlier days of computing, switches, punched holes and punched paper tapes were used to represent binary values. In a modern computer, the numeric values may be represented by two different voltages; on a magnetic disk, magnetic polarities may be used. A "positive", "yes", or "on" state is not necessarily equivalent to the numerical value of one; it depends on the architecture in use.

In keeping with customary representation of numerals using Arabic numerals, binary numbers are commonly written using the symbols 0 and 1. When written, binary numerals are often subscripted, prefixed or suffixed in order to indicate their base, or radix. The following notations are equivalent:

- 100101 binary (explicit statement of format)
- 100101b (a suffix indicating binary format; also known as Intel convention)
- 100101B (a suffix indicating binary format)
- bin 100101 (a prefix indicating binary format)
- 1001012 (a subscript indicating base-2 (binary) notation)
- %100101 (a prefix indicating binary format; also known as Motorola convention)
- 0b100101 (a prefix indicating binary format, common in programming languages)
- 6b100101 (a prefix indicating number of bits in binary format, common in programming languages)

When spoken, binary numerals are usually read digit-by-digit, in order to distinguish them from decimal numerals. For example, the binary numeral 100 is pronounced one zero zero, rather than one hundred, to make its binary nature explicit, and for purposes of correctness. Since the binary numeral 100 represents the value four, it would be confusing to refer to the numeral as one hundred (a word that represents a completely different value, or amount). Alternatively, the binary numeral 100 can be read out as "four" (the correct value), but this does not make its binary nature explicit.

### Counting in Binary

Decimal number | Binary number |

0 | 0 |

1 | 1 |

2 | 10 |

3 | 11 |

4 | 100 |

5 | 101 |

6 | 110 |

7 | 111 |

8 | 1000 |

9 | 1001 |

10 | 1010 |

11 | 1011 |

12 | 1100 |

13 | 1101 |

14 | 1110 |

15 | 1111 |

Counting in binary is similar to counting in any other number system. Beginning with a single digit, counting proceeds through each symbol, in increasing order. Before examining binary counting, it is useful to briefly discuss the more familiar decimal counting system as a frame of reference.

### Binary Counting

Binary counting follows the same procedure, except that only the two symbols 0 and 1 are available. Thus, after a digit reaches 1 in binary, an increment resets it to 0 but also causes an increment of the next digit to the left:

**0000,**

**0001, (rightmost digit starts over, and next digit is incremented)**

**0010, 0011, (rightmost two digits start over, and next digit is incremented)**

**0100, 0101, 0110, 0111, (rightmost three digits start over, and the next digit is incremented)**

**1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, ...**

In the binary system, each digit represents an increasing power of 2, with the rightmost digit representing 20, the next representing 21, then 22, and so on. The value of a binary number is the sum of the powers of 2 represented by each "1"β―digit. For example, the binary number 100101 is converted to decimal form as follows:

**1001012 = [ ( 1 ) Γ 25 ] + [ ( 0 ) Γ 24 ] + [ ( 0 ) Γ 23 ] + [ ( 1 ) Γ 22 ] + [ ( 0 ) Γ 21 ] + [ ( 1 ) Γ 20 ]**

**1001012 = [ 1 Γ 32 ] + [ 0 Γ 16 ] + [ 0 Γ 8 ] + [ 1 Γ 4 ] + [ 0 Γ 2 ] + [ 1 Γ 1 ]**

**1001012 = 3710**

### Binary Arithmetic

Arithmetic in binary is much like arithmetic in other numeral systems. Addition, subtraction, multiplication, and division can be performed on binary numerals.

### Addition

The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:

**0 + 0 β 0**

**0 + 1 β 1**

**1 + 0 β 1**

**1 + 1 β 0, carry 1 (since 1 + 1 = 2 = 0 + (1 Γ 21) )**

Adding two "1" digits produces a digit "0", while 1 will have to be added to the next column. This is similar to what happens in decimal when certain single-digit numbers are added together; if the result equals or exceeds the value of the radix (10), the digit to the left is incremented:

**5 + 5 β 0, carry 1 (since 5 + 5 = 10 = 0 + (1 Γ 101) )**

**7 + 9 β 6, carry 1 (since 7 + 9 = 16 = 6 + (1 Γ 101) )**

This is known as carrying. When the result of an addition exceeds the value of a digit, the procedure is to "carry" the excess amount divided by the radix (that is, 10/10) to the left, adding it to the next positional value. This is correct since the next position has a weight that is higher by a factor equal to the radix. Carrying works the same way in binary:

**1 1 1 1 1 (carried digits)**

** 0 1 1 0 1**

**+ 1 0 1 1 1**

**-------------**

**= 1 0 0 1 0 0 = 36**

In this example, two numerals are being added together: 011012 (1310) and 101112 (2310). The top row shows the carry bits used. Starting in the rightmost column, 1 + 1 = 102. The 1 is carried to the left, and the 0 is written at the bottom of the rightmost column. The second column from the right is added: 1 + 0 + 1 = 102 again; the 1 is carried, and 0 is written at the bottom. The third column: 1 + 1 + 1 = 112. This time, a 1 is carried, and a 1 is written in the bottom row. Proceeding like this gives the final answer 1001002 (36 decimal).

When computers must add two numbers, the rule that: x xor y = (x + y) mod 2 for any two bits x and y allows for very fast calculation, as well.

### Addition Table

0 | 1 | |

0 | 0 | 1 |

1 | 1 | 10 |

### Subtraction

Further information: signed number representations and two's complement

Subtraction works in much the same way:

**0 β 0 β 0**

**0 β 1 β 1, borrow 1**

**1 β 0 β 1**

**1 β 1 β 0**

Subtracting a "1" digit from a "0" digit produces the digit "1", while 1 will have to be subtracted from the next column. This is known as borrowing. The principle is the same as for carrying. When the result of a subtraction is less than 0, the least possible value of a digit, the procedure is to "borrow" the deficit divided by the radix (that is, 10/10) from the left, subtracting it from the next positional value.

** * * * * (starred columns are borrowed from)**

** 1 1 0 1 1 1 0**

** β 1 0 1 1 1**

**----------------**

**= 1 0 1 0 1 1 1**

** * (starred columns are borrowed from)**

** 1 0 1 1 1 1 1**

**- 1 0 1 0 1 1**

**----------------**

**= 0 1 1 0 1 0 0**

Subtracting a positive number is equivalent to adding a negative number of equal absolute value. Computers use signed number representations to handle negative numbersβmost commonly the two's complement notation. Such representations eliminate the need for a separate "subtract" operation. Using two's complement notation subtraction can be summarized by the following formula:

**A β B = A + not B + 1**

## Comments (2)

## Jordan

great solutions...

## Jordan

great solutions...