binary addition

10
Binary addition Here is you answer. First in binary, then after in plain text. 11011 + 111001 + 1001 + 11001 = 1101100 27+47+9+25=108 Now , how to create binary... look at the below table... Notice how each number is twice the number above it. (for example... x and underneath is is x+x) 1 2 4 8 16 32 64 128 256 512

Upload: rolan-ambrocio

Post on 04-Jan-2016

212 views

Category:

Documents


0 download

DESCRIPTION

ref

TRANSCRIPT

Page 1: Binary Addition

Binary addition

Here is you answer. First in binary, then after in plain text.

11011 + 111001 + 1001 + 11001 = 1101100

27+47+9+25=108

Now , how to create binary... look at the below table... Notice how each number is twice the number above it. (for example... x and underneath is is x+x)

1

2

4

8

16

32

64

128

256

512

Now, binary is a means of translating numbers into simple 1 (on/true) and 0 (off/false). This is why it is best for computer language, the computer can understand on and off signals.

Page 2: Binary Addition

To convert a number to binary, see this next demonstration...

lets say we want to figure out the number 22....

(read this from the bottom up...)

1 = 0 (false, there is no 1's in 0)

2 = 1 (true, there is one 2 in 2, this leaves 0 left)

4 = 1 (true, there is one 4 in 6, this leaves 2 left)

8 = 0 (false, there are zero 6's in 8)

16 = 1 (true, there is one 16 in 22, this leaves 6 left)

32 = 0 (false, there are zero 32's in 22)

so, counting the 0s and 1s from the bottom, you would read 22 as....

010110

Subtraction binary complimenting

Binary subtraction is the same in the case of signed and unsigned numbers. Just that in the case of unsigned numbers, we ignore the sign bit, while in the case of signed numbers we do care about the sign bit.

Use the following steps for binary subtraction: (Assume the two numbers are x and y)

1. Take one of the two numbers that we are subtracting and take the complement of it.

2. Add this to the other operand and add 1 to it.

E.g: If we have two numbers x and y,

Page 3: Binary Addition

In step 1, we get ~x i.e. complement of x.

In step 2, we compute ~x + y + 1 to get the result of subtraction.

I hope the method is clear.

Solved example 1:

0100 - 0011

1. Take complement of 0011 = 1100

2. Add 0100 + 1100 + 1 = 10001

Things to note are:

The extra bit (first from the left) we have is the carry-out = 1

The sign bit (second from left) we have is = 0 .. so the number is positive.

ANS = 0001 (1 in decimal)

If you are told that the numbers are signed, we take the sign bit into consideration.

If the bit is unsigned, we don't care about the signed bit.

In this case, we get the same answer.

Solved example 2:

0011 - 0100

1. Take complement of 0100 = 1011

2. Add 0011 + 1011 + 1 = 1111

Page 4: Binary Addition

Things to note are:

The extra bit (first from the left) we have is the carry-out = 0

The sign bit (second from left) we have is = 1 .. so the number is negative. So, we get the absolute value is ~(1111)+1 = 0001

ANS = 0001 (-1 in decimal)

If you are told that the numbers are signed, we take the sign bit into consideration.

If the bit is unsigned, we don't care about the signed bit. So, in that case, we get 1 and not -1.

Please check the rules for signed and unsigned that your book follows. It has different implementations as well.

Binary multiplication

For binary multiplication, remember that binary operates in the base 2 system. With that said, the only multiplication facts you need to remember are 0 x 0 = 0 ,0 x 1 = 0 ,1 x 0 = 0 ,1 x 1 = 1 . Work the problem the same as you would for multiplying decimal numbers. 10101010 * 1, write your answer, next line would have a place holder 0 then multiply by the next number. After you multiply by all numbers, add the answer columns up and you'll have your answer.

Digital is all based on logic, don't over think it!

101

x11

_____

101

1010 <-- the 0 here is the placeholder THIS IS JUST AN EXAMPLE

Binary division

1010001-------------(binary)

=(1x2^6)+(0x2^5)+(1x2^4)+(0x2^3)

Page 5: Binary Addition

+(0x2^2)+(0x2^1)+(1x2^0)

=81--------(decimal)

11-------------(binary)

=(1x2^1)+(1x2^0)

=3-------------(decimal)

1010001 / 11 (change binary to decimal)

=81/3

=27 (change decimal to binary)

=11011

Explanation:

27-------------decimal

27/2=13------1(remainder a1)

13/2=6--------1(remainder a2)

6/2=3-----------0(remainder a3)

3/2=1-----------1(remainder a4)

1/2=0-----------1(remainder a5)

The remainder must count from

bottom to top that is

a5 a4 a3 a2 a1 = 11011

and this is the binary number for

Page 6: Binary Addition

decimal 27.

(i)

110111 / 1011 (change binary to decimal)

=55/11

=5 (change decimal to binary)

=101

(ii)

111.0000------------(binary)

=(1x2^2)+(1x2^1)+(1x2^0)+(0x2^-1)

+(0x2^-2)+(0x2^-3)+(0x2^-4)

=7----------------(decimal)

1.01----------------(binary)

=(1x2^0)+(0x2^-1)+(1x2^-2)

=1.25------------(decimal)

7/1.25=5.6-----------(decimal)

5.6=5+0.6---------(decimal)

CHANGE DECIMAL 5.6 TO BINARY:-

Page 7: Binary Addition

Take number 5 first,

5/2=2-------1(remainder a1)

2/2=1--------0(remainder a2)

1/2=0--------1(remainder a3)

Count from bottom to top

a3 a2 a1

5=101

(101 is binary number for decimal 5)

Then take number 0.6

0.6x2=(1).2 (a-1=1)

0.2x2=(0).4 (a-2=0)

0.4x2=(0).8 (a-3=0)

0.8x2=(1).6 (a-4=1)

0.6x2=(1).2 (a-5=1)---[process starts

repeating here because

1.2 was previously obtained.]

0.2x2=(0).4 (a-6=0)

0.4x2=(0).8 (a-7=0)

0.8x2=(1).6 (a-8=1)

Count from top to bottom

a-1 a-2 a-3 a-4 a-5 a-6 a-7 a-8 ......

0.6=10011001..............

(10011001..... is binary number for decimal 0.6)

Page 8: Binary Addition

Explanation: Count from top to bottom

a-1 a-2 a-3 a-4 a-5 a-6 a-7 a-8 is 10011001

and this number is repeating it self so

we no need to continue.

In nomal case we will stop when the answer

is 1.0 because we take out the left number

that is 1 and left behind 0. Because

0 multiply by any number also get answer 0.

This is the reason we will stop when the

answer is 1.0

So,

5.6----------(decimal)

=a3 a2 a1 . a-1 a-2 a-3 a-4 a-5 a-6 a-7 a-8 .....

=101.10011001..... ---------(binary)

5.6 = 101.1001100110011001.......

So, 5.6 is decimal and

101.1001100110011001..........

is binary for 5.6

scientific and engineer notaion

Both notations use the exponential notation but scientific notation allows one digit to the left of the decimal while engineering notation will allow three digits to the left of the decimal while keeping the exponential term as a multiple of three.

Page 9: Binary Addition

number:1345765.3

scientific: 1.3457653E+06

engineering: 1.3457653E+06

number: 0.01655

scientific: 1.655E-02

engineering: 16.55E-03

number: 14500

scientific: 1.4500E+04

engineering: 14.500E+03

The engineering notation allows for a relative easy comparison of numbers in terms of standard units of thousands (e.g. ksi, kg) and millions (e.g. msi, MPa).