Information Processing Session 5B Binary Arithmetic Slide 000001.
-
date post
15-Jan-2016 -
Category
Documents
-
view
237 -
download
0
Transcript of Information Processing Session 5B Binary Arithmetic Slide 000001.
![Page 1: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/1.jpg)
Information Processing
Session 5BBinary Arithmetic
Slide 000001
![Page 2: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/2.jpg)
Objectives After studying this week’s work, you
should: gain insight into how the processor
deals with information at the bit level Understand numbers written in binary
form Be able to convert numbers from binary
to decimal notation and vice-versa Be able to add numbers in binary form
Slide 000010
![Page 3: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/3.jpg)
Bits A bit is the smallest piece
of information in the computer
At a single location, the information is either One - current is ON Zero - current is OFF
There are no in-between states
ON
OFF
Slide 000011
![Page 4: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/4.jpg)
Bytes The way that
information is coded is to use a sequence of zeros and ones
It is usual to have a sequence of 8 bits collected together
This is called a byte 10110101
Slide 000100
![Page 5: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/5.jpg)
Bits and Bytes Depending upon the
design of the computer, there could be 4, 8 16, 32, 64 (or even more!) bits processed by the computer at once
For the next few slides we will look at a simple 4-bit device.
Slide 000101
![Page 6: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/6.jpg)
A 4-bit register Reading from the
right, each bit is worth double the one preceding it.
The sequence, reading from the right is: 1,2,4,8, ...
If we had more bits, it would continue: ... 16, 32, 64, etc.
148 2
4
is ON
1
is ON
Slide 000110
![Page 7: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/7.jpg)
Binary Numbers The register shown on
the right represents the binary number 0101
This has ones in the 1 and 4 cells, and zeroes in the others.
The number represented is 5
148 2
4 1
Slide 000111
0101
4+1 = 5
![Page 8: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/8.jpg)
Counting in Binary Counting is an
automatic process Follow the
sequence...
Slide 001000
![Page 9: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/9.jpg)
Counting in Binary A pulse enters on
the right
Slide 001001
![Page 10: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/10.jpg)
Counting in Binary To begin with the
first cell was OFF
It is flipped to ON
Slide 001010
![Page 11: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/11.jpg)
Counting in Binary Another pulse
enters on the right
Slide 001011
![Page 12: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/12.jpg)
Counting in Binary The first cell was
ON. It is flipped to OFF The pulse moves
to the next cell on the left
Slide 001100
![Page 13: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/13.jpg)
Counting in Binary The next cell on
the left was OFF That cell is flipped
to ON
Slide 001101
![Page 14: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/14.jpg)
Counting in Binary Another pulse
enters from the right
Slide 001110
![Page 15: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/15.jpg)
Counting in Binary The first cell was
OFF
It is flipped to ON
Slide 001111
![Page 16: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/16.jpg)
Counting in Binary Another pulse
enters from the right
Slide 010000
![Page 17: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/17.jpg)
Counting in Binary The first cell was
ON, and is flipped to OFF
The pulse moves to the second cell
Slide 010001
![Page 18: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/18.jpg)
Counting in Binary The second cell
was ON, and is flipped to OFF
the pulse moves to the third cell
Slide 010010
![Page 19: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/19.jpg)
Counting in Binary The third cell was
OFF and is flipped to ON
Slide 010011
![Page 20: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/20.jpg)
Counting in Binary Follow the
sequence on the right, and try to continue it.
you will see that the switching creates a pattern off ON/OFF in each column
0001
0010
0011
0100
0101
0110
Slide 010100
![Page 21: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/21.jpg)
Counting in Binary The 1’s column
alternates 1,0,1,0 etc. The 2’s column starts
at 2 and alternates two 1’s, two 0’s
The 4’s column starts at 4, and alternates four 1’s, four 0’s
The 8’s column starts at 8 and alternates eight 1’s eight 0’s
0001
0010
0011
0100
0101
0110
Slide 010101
![Page 22: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/22.jpg)
Decimal Numbers By decimal, we simply mean that
the numbers are written in powers of ten
These are 1, 10, 100, 1000, etc. So that:
352 = 300 + 50 + 2
100 10 1
3 5 2
Slide 010110
![Page 23: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/23.jpg)
Binary Numbers By Binary, we mean that numbers
are written in powers of two These are 1, 2, 4, 8, 16 etc. So that:
10100 = Which is 16 + 4 = 20
16 8 4 2 1
1 0 001
Slide 010111
![Page 24: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/24.jpg)
Converting Binary to Decimal Example: 101101 Reading from right to left the columns are
1,2,4,8 etc.
i.e. 32 16 8 4 2 11 0 1 1 0 1
So the number in decimal notation is:
32 + 8 + 4 + 1 = 45
Slide 011000
![Page 25: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/25.jpg)
How do we convert Decimal to Binary? There is a specific
technique which allows us to do this.
It involves repeatedly dividing a number by two and noting the remainder.
Slide 011001
![Page 26: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/26.jpg)
Converting Decimal to Binary:An example
Convert 117 to binary: 117÷ 2 = 58 remainder 1 58 ÷ 2 = 29 remainder 0 29 ÷ 2 = 14 remainder 1 14 ÷ 2 = 7 remainder 0 7 ÷ 2 = 3 remainder 1 3 ÷ 2 = 1 remainder 1 1 ÷ 2 = 0 remainder 1
In binary the number is: 1110101
Slide 011010
![Page 27: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/27.jpg)
Adding In Binary Addition in binary
is a direct counterpart of what happens at the processor level.
First of all we will look at a numerical example
Slide 011011
![Page 28: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/28.jpg)
Adding in Binary There are only four
possible combinations.
The first three are “obvious”
The last one is special (remember 1 + 1 = 2, which is 10 in binary)
0 + 0 = 0 0 + 1 = 1 1 + 0 = 1
1 + 1 = 0, carry 1
Slide 011100
![Page 29: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/29.jpg)
Adding in Binary Adding
10111 +11101
01
1 + 1 = 2This is 10 in BinaryPut 0 in the answer, carry 1
Slide 011101
![Page 30: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/30.jpg)
Adding in Binary Adding
1 0 1 1 1 +1 1 1 0 1 0 0 1 1
1 + 0 + 1= 2This is 10 in BinaryPut 0 in the answer, carry 1
Slide 011110
![Page 31: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/31.jpg)
Adding in Binary Adding
1 0 1 1 1 +1 1 1 0 1 1 0 0 1 1 1
1 + 1 + 1= 3This is 11 in BinaryPut 1 in the answer, carry 1
Slide 011111
![Page 32: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/32.jpg)
Adding in Binary Adding
1 0 1 0 1 +1 1 1 0 1 1 0 0 1 1 1
Carry on with this…
Slide 100000
![Page 33: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/33.jpg)
Adding in Binary The answer:
1 0 1 1 1 +1 1 1 0 1
1 1 0 1 0 0
1 1 1 1 1
Slide 100001
![Page 34: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/34.jpg)
The Binary Adder We will add
0011 (3) 0110 (6)
Slide 100010
![Page 35: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/35.jpg)
The Binary Adder Starting with the
end column, top cell is ON
This pulse enters into the bottom cell
Slide 100011
![Page 36: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/36.jpg)
The Binary Adder The bottom cell
was OFF
The pulse causes it to flip to ON
Slide 100100
![Page 37: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/37.jpg)
The Binary Adder The next top cell
was ON The pulse enters
into the bottom cell
Slide 100101
![Page 38: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/38.jpg)
The Binary Adder The bottom cell
was ON The pulse flips it to
OFF The pulse moves
to the next cell
Slide 100110
![Page 39: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/39.jpg)
The Binary Adder The next cell is ON The pulse flips it to
OFF The pulse moves
to the next cell
Slide 100111
![Page 40: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/40.jpg)
The Binary Adder The next cell is
OFF The pulse flips it to
ON
Slide 101000
![Page 41: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/41.jpg)
The Binary Adder The bottom line
now reads:
1001
This is 8 + 1= 9
Slide 101001
![Page 42: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/42.jpg)
Bits and Bytes We have seen that
a 4-bit register can count from 0 [0000] to 15 [1111]
This means that it has 16 different states.
Slide 101010
![Page 43: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/43.jpg)
Bits and Bytes Each bit in the
register can be ON or OFF. This means that there are two possibilities for each cell
That is, altogether 2 x 2 x 2 x 2 = 16 states
Slide 101011
2222
2 x 2 x 2 x 2 = 24
![Page 44: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/44.jpg)
Bits and Bytes The number of
possible states of registers of other sizes can be worked out in the same way
For example an 8-bit register (byte) has 2x2x2x2x2x2x2x2=
28 = 256 different states.
Bits States
1 22 44 168 25616 65,53632
4,294,987,296Slide 101100
![Page 45: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/45.jpg)
Megabits and Kilobytes A Kilobyte is 210
bytes. This is the nearest power of two to 1000. In fact 210 = 1024
A megabit is 220 bits. This is the nearest power of 2 to 1 million. In fact 220 = 1048576
Slide 101101
![Page 46: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/46.jpg)
Other Bases Decimal and Binary
are two different number bases used by the computer, but there are others
An important one is Hexadecimal which has 16 separate characters: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Slide 101110
![Page 47: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/47.jpg)
Hexadecimal The extra letters are so that
the numbers 10-15 can be written using one character each. This means that A8BC is a number written in Hexadecimal.
These numbers are written in base 16, so that a number like 9E means the 9 is 9 x 16 = 144 the E is 14 x 1 = 14
Altogether this would be 158
Dec Hex0 01 12 23 34 45 56 67 78 89 910 A11 B12 C13 D14 E15 F
Slide 101111
![Page 48: Information Processing Session 5B Binary Arithmetic Slide 000001.](https://reader035.fdocuments.us/reader035/viewer/2022081503/56649d4d5503460f94a2bc99/html5/thumbnails/48.jpg)
Summary A bit has two states, ON or OFF, which
means that at the core of a computer we need to use binary coding of numbers (powers of two)
Registers count and add using in binary code
There are algorithms for converting decimal to binary and vice-versa
Binary addition has only four possible addition pairs, and a “carrying rule”
Slide 110000