Addition subtraction multiplication and division of binary numbers pdf


Subtracting 1 from P gives us 4. Next, subtract 16 from 23, to get 7. Subtract 1 from P gives us 3. Subtract 1 from P to get 1. Subtract 1 from P to get 0. Subtract 1 from P to get P is now less than zero, so we stop.

Another algorithm for converting decimal to binary However, this is not the only approach possible. We can start at the right, rather than the left.

This gives us the rightmost digit as a starting point. Now we need to do the remaining digits. One idea is to "shift" them. It is also easy to see that multiplying and dividing by 2 shifts everything by one column: Similarly, multiplying by 2 shifts in the other direction: Take the number Dividing by 2 gives Since we divided the number by two, we "took out" one power of two. Also note that a1 is essentially "remultiplied" by two just by putting it in front of a[0], so it is automatically fit into the correct column.

Now we can subtract 1 from 81 to see what remainder we still must place Dividing 80 by 2 gives We can divide by two again to get This is even, so we put a 0 in the 8's column. Since we already knew how to convert from binary to decimal, we can easily verify our result. These techniques work well for non-negative integers, but how do we indicate negative numbers in the binary system?

Before we investigate negative numbers, we note that the computer uses a fixed number of "bits" or binary digits. An 8-bit number is 8 digits long. For this section, we will work with 8 bits. The simplest way to indicate negation is signed magnitude. To indicate , we would simply put a "1" rather than a "0" as the first bit: In one's complement, positive numbers are represented as usual in regular binary. However, negative numbers are represented differently.

To negate a number, replace all zeros with ones, and ones with zeros - flip the bits. Thus, 12 would be , and would be As in signed magnitude, the leftmost bit indicates the sign 1 is negative, 0 is positive. To compute the value of a negative number, flip the bits and translate as before. Begin with the number in one's complement. Add 1 if the number is negative. Twelve would be represented as , and as To verify this, let's subtract 1 from , to get If we flip the bits, we get , or 12 in decimal.

In this notation, "m" indicates the total number of bits. Then convert back to decimal numbers. The logical values true and false can be combined using logic operations , such as and , or, and not.

Vectors can be added and subtracted. Rotations can be combined using the function composition operation, performing the first rotation and then the second. Operations on sets include the binary operations union and intersection and the unary operation of complementation.

Operations on functions include composition and convolution. Operations may not be defined for every possible value. For example, in the real numbers one cannot divide by zero or take square roots of negative numbers. The values for which an operation is defined form a set called its domain. The set which contains the values produced is called the codomain , but the set of actual values attained by the operation is its range.

For example, in the real numbers, the squaring operation only produces non-negative numbers; the codomain is the set of real numbers, but the range is the non-negative numbers.

Operations can involve dissimilar objects. A vector can be multiplied by a scalar to form another vector. And the inner product operation on two vectors produces a scalar. An operation may or may not have certain properties, for example it may be associative , commutative , anticommutative , idempotent , and so on. The values combined are called operands , arguments , or inputs , and the value produced is called the value , result , or output. Operations can have fewer or more than two inputs.

An operation is like an operator , but the point of view is different. The sets X k are called the domains of the operation, the set Y is called the codomain of the operation, and the fixed non-negative integer k the number of arguments is called the type or arity of the operation. Thus a unary operation has arity one, and a binary operation has arity two.

An operation of arity zero, called a nullary operation, is simply an element of the codomain Y. An operation of arity k is called a k -ary operation. The above describes what is usually called a finitary operation, referring to the finite number of arguments the value k.

There are obvious extensions where the arity is taken to be an infinite ordinal or cardinal , or even an arbitrary set indexing the arguments.