Download presentation
Presentation is loading. Please wait.
Published byJasper Butler Modified over 9 years ago
1
Lecture for Week 9 2013 Spring
2
Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday life. The decimal system is an example of a positional number system. Each digit has a place value that depends on its position with respect to the decimal point. The Binary Number System
3
Example: 2386.75 = 2*10 3 +3*10 2 +8*10+6*10 0 +7*10 -1 +5*10 -2 where 6 represents number of units, 8 number of tens, 3 number of hundreds, 2 number of thousands To the right of decimal point we have 7 number of tenths, 5 number of hundredths, and so on. The Binary Number System
4
The decimal system is said to use a base of 10 because the place values are powers of 10. Because we use the decimal system all the time it is easy to forget that there is no mathematical reason for using powers of 10 as the place values. The choice of 10 probably arose because people used their 10 fingers for counting. But in fact we can use any number as the base of a positional number system. A familiar example of non-decimal number system is the subdivision of an hour into 60mins, a minute into 60sec. 2 h 26 m 35 s = 2*60 2 + 26*60 1 + 35*60 0 The Binary Number System
5
It turns out that in Computing bases 2, 8 and 16 are particularly useful. Base 2 is the binary number system Base 8 is the octal number system Base 16 is the hexadecimal number system The binary number system is a positional number system that uses 2 as the base. For the purpose of this course we shall be working only with non-negative integers ( Z + {0} ). The Binary Number System
6
Example: 10110 2 = 1*2 4 +0*2 3 +1*2 2 +1*2 1 +0*2 0 = 16 + 0 + 4 + 2 +0 = 22 Note that subscript 2 represents base 2 and it is necessary to state it unless we work in the decimal number system. (Expressing negative numbers or real numbers is not really any different) The Binary Number System
7
The table shows the integers from 0 to 20 in their binary representation The Binary Number System BinaryDecimalBinaryDecimal 0 1 10 11 100 101 110 111 1000 1001 1010 0 1 2 3 4 5 6 7 8 9 10 1011 1100 1101 1110 1111 10000 10001 10010 10011 10100 11 12 13 14 15 16 17 18 19 20
8
The binary system uses the 2 binary digits 0 and 1. Every number in binary will appear as strings of zeros and ones. In octal as strings of 0,1,2,…7 In decimal as strings of 0,1,2,…,9 In hexadecimal as strings of 0,1,2,…,9,A,B,C,D,E,F where A represents 10, B represents 11, C represents 12, D represents 13, E represents 14 and F represents 15. The Binary Number System
9
Base-10 number system Consist of ten numbers- 0 to 9 Common type of number system used everyday. Examples- (20) 10, (50) 10, (145) 10, etc. Decimal number system
10
From the table we can see that 1. odd numbers end with 1 2. even numbers end with 0 These two lines can be summarised as follows: The last digit in the binary representation is the remainder after dividing the number by 2. Conversion from Decimal to Binary
11
So the first step is to divide (integer division) n by 2 to obtain quotient and remainder (both whole numbers and remainder can only be 0 or 1). Quotient remainder form PASCAL notation: N DIV 2 = quotient(7 DIV 2 = 3) N MOD 2 = remainder. (7 MOD 2 = 1) Conversion from Decimal to Binary
12
In order to proceed further we make another observation By removing the rightmost digit in a binary representation we obtain the binary representation of n DIV 2. Conversion from Decimal to Binary
13
Example1: 14 = 1110 2 removing last digit (0) we obtain 111 which in base 10 represents 7. 14 DIV 2 = 7 Example2 11 = 1011 2 removing last digit (1) we obtain 101 which in base 10 represents 5. 11 DIV 2 = 5 ( DIV only returns quotient) Conversion from Decimal to Binary
14
Each time we perform division we record remainder until n DIV 2 (quotient) becomes zero. Then we return the string of remainders in reverse order. Conversion from Decimal to Binary
15
Convert (250) 10 to binary 250/2=125remainder is 0 125/2=62remainder is 1 62/2=31remainder is 0 31/2=15remainder is 1 15/2=7remainder is 1 7/2=3remainder is 1 3/2=1remainder is 1 1/2=0remainder is 1 Therefore ….(250) 10 =(11111010) 2 Decimal to binary Conversion
16
Convert 25 into binary. 25 = 12*2+1 12 = 6*2+0 6 = 3*2+0 3 = 1*2+1 1 = 0*2+1 Therefore, 25 = (11001) 2 Decimal to binary Conversion
17
Taking binary number as (11111010)2 0×2 0 =0 1 ×2 1 =2 0 ×2 2 =0 1 ×2 3 =8 1 ×2 4 =16 1 ×2 5 =32 1 ×2 6 =64 1 ×2 7 =128 Adding the numbers we get…0+2+0+8+16+32+64+128=250 Therefore….(11111010) 2 =(250) 10 Binary to decimal Conversion
18
Convert the following as indicated 1.34 to binary 2.64 to binary 3.123 to binary 4.111000 to decimal 5.10101010 to decimal 6.101110011 to decimal 7.878 to binary Practice Problem
19
Adding binary numbers is a very simple task, and very similar to the longhand addition of decimal numbers. As with decimal numbers, you start by adding the bits (digits) one column, or place weight, at a time, from right to left. Unlike decimal addition, there is little to memorize in the way of rules for the addition of binary bits: Addition and Multiplication in Binary 0 + 0 = 0 1 + 0 = 1 0 + 1 = 1 1 + 1 = 10 1 + 1 + 1 = 11
20
Just as with decimal addition, when the sum in one column is a two-bit (two-digit) number, the least significant figure is written as part of the total sum and the most significant figure is "carried" to the next left column. Consider the following examples: Addition and Multiplication in Binary
21
The addition problem on the left did not require any bits to be carried, since the sum of bits in each column was either 1 or 0, not 10 or 11. In the other two problems, there definitely were bits to be carried, but the process of addition is still quite simple. Addition and Multiplication in Binary
22
Binary multiplication is actually much simpler than decimal multiplication. In the case of decimal multiplication, we need to remember 3 x 9 = 27, 7 x 8 = 56, and so on. In binary multiplication, we only need to remember the following, Binary multiplication 0 x 0 = 0 0 x 1 = 0 1 x 0 = 0 1 x 1 = 1
23
Note that since binary operates in base 2, the multiplication rules we need to remember are those that involve 0 and 1 only. 101 x11 First we multiply 101 by 1, which produces 101. Then we put a 0 as a placeholder as we would in decimal multiplication, and multiply 101 by 1, which produces 101. 101 x11 101 1010 <-- the 0 here is the placeholder Binary multiplication
24
The next step, as with decimal multiplication, is to add. The results from our previous step indicates that we must add 101 and 1010, the sum of which is 1111. 101 x11 101 1010 1111 Binary multiplication
25
Multiply 11010 and 1011
26
Multiply the following: 1.1011 x 11 2.110 x 101 3.111 x 10 4.1110 x 1101 5.10110 x 101 Practice Problem
27
Subtraction ( and division) of binary numbers is performed in the same way as with decimal numbers. Binary subtraction is simplified as well, as long as we remember how subtraction and the base 2 number system. Let's first look at an easy example. Subtraction and Division
28
Since addition is opposite operation of subtraction the table for subtraction can be deduced from the addition table. 0 + 0 = 0 then 0 - 0 = 0; 1 + 0 = 1 then 1 - 0 = 1; 0 + 1 = 1 then 1 - 1 = 0; 1 + 1 = 0 (and 'carry' 1) then 0 - 1 = 1 ( and 'borrow' 1 from the next position ). Subtraction and Division
29
Note that the difference is the same if this was decimal subtraction. Also similar to decimal subtraction is the concept of "borrowing." Watch as "borrowing" occurs when a larger digit, say 8, is subtracted from a smaller digit, say 5, as shown below in decimal subtraction. Subtraction and Division
30
For 10 minus 1, 1 is borrowed from the "tens" column for use in the "ones" column, leaving the "tens" column with only 2. The following examples show "borrowing" in binary subtraction. Subtraction and Division
31
Binary division is almost as easy, and involves our knowledge of binary multiplication. Take for example the division of 1011 into 11. Subtraction and Division
32
To check our answer, we first multiply our divisor 11 by our quotient 11. Then we add its' product to the remainder 10, and compare it to our dividend of 1011. The sum is equal to our initial dividend, therefore our solution is correct. Subtraction and Division
33
Complements are used for storing numbers in the computer as well as for subtraction. In subtraction instead of calculating A - B we can add A to 1-complement of B plus 1 or by adding 2-complement of B to A. Unfortunately, this method needs a little bit more refining. Before we continue with it we first define complements of a binary number. One's and Two's Complements
34
One's complement of a binary number A is a binary number obtained by subtracting each digit of A from 1. Alternatively, one's complement of a binary number A is a binary number such that: Each digit of A is changed into its opposite (i.e. 1 into 0, 0 into 1) One's and Two's Complements
35
Example 1's complement of 110101 is 001010 Two's complement of a binary number A is a binary number obtained by adding 1 to one's complement of A. Example From the above example A is 110101 Then 1's compl. is 001010 2's compl. is 001010 + 1 ----------- 001011 One's and Two's Complements
36
Any questions
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.