COMPUTING FUNDAMENTALS Instructor Romana Farhan Lecture 02 Romana

  • Slides: 49
Download presentation
COMPUTING FUNDAMENTALS Instructor: Romana Farhan Lecture # 02 Romana. farhan@uettaxila. edu. pk

COMPUTING FUNDAMENTALS Instructor: Romana Farhan Lecture # 02 Romana. farhan@uettaxila. edu. pk

� How do computers represent data? � Number systems � Binary number system �

� How do computers represent data? � Number systems � Binary number system � Binary Arithmetic

�CPU consists of several million tiny electronic switches called transistors, that can be turned

�CPU consists of several million tiny electronic switches called transistors, that can be turned on or off. � Computers know two distinct physical states ◦ Switch is on or off � Since these switches only have two states, ◦ it makes sense for a computer to perform its computations with a number system that only has two digits. ◦ the binary number system.

◦ A manner of counting ◦ Several different number systems exist � Decimal number

◦ A manner of counting ◦ Several different number systems exist � Decimal number system ◦ Used by humans to count ◦ Contains ten distinct digits (0 -9) ◦ Digits combine to make larger numbers

� Binary number system ◦ Used by computers to count ◦ Two distinct digits,

� Binary number system ◦ Used by computers to count ◦ Two distinct digits, 0 and 1 corresponding to off or on state of switch. ◦ 0 and 1 combine to make numbers ◦ With only these two digits, a computer can perform all the arithmetic that we can with ten digits ◦ Goal of our study is to know �Converting between binary and decimal, �Performing binary arithmetic,

base of any number system is determined by the number of digits in the

base of any number system is determined by the number of digits in the system. � For example �The ◦ ◦ Binary is a base 2 number system Decimal is a base 10 number system Octal ? ? ? Hexadecimal ? ? ? �Distinguish between various number systems by putting a small subscript after the number to indicate the base.

� For example ◦ 462. 1510 ◦ 110. 112 � we need to understand

� For example ◦ 462. 1510 ◦ 110. 112 � we need to understand the relationship between the digits of a given number, ◦ the position of those digits, and the base of the number system. ◦ Let's take another look at our example number in the decimal system.

� Generalized formula

� Generalized formula

� In decimal system value of number is defined by both the number and

� In decimal system value of number is defined by both the number and its position. � Most significant bit/digit (MSB, MSD) ◦ The digit in a number which can affect the number Significantly ◦ It is the non zero digit of a number that is in the farthest left. � The least significant bit/ digit (LSB, LSD) ◦ It is the digit in a number that has the least effect on that number.

◦ Any changes in the LSD will have minimal effect on the value. ◦

◦ Any changes in the LSD will have minimal effect on the value. ◦ It is the non zero digit of a number that is farthest right. ◦ For example

� To convert a decimal number to a binary number, � The decimal number

� To convert a decimal number to a binary number, � The decimal number is successively divided by 2. � Follow the following steps 1. Divide the decimal number by 2 and note the remainder. 2. Divide the quotient you got from the previous division once again by 2 and note the remainder. For each step, the division results in a remainder of 1 or 0.

3. Repeat step 2 until the quotient becomes 1. 4. The binary number is

3. Repeat step 2 until the quotient becomes 1. 4. The binary number is obtained by ordering the 1 s and 0 s obtained as remainders from bottom to top.

� To convert the fractional part of the decimal number to a binary number,

� To convert the fractional part of the decimal number to a binary number, the fractional part is repeatedly multiplied by 2. � Follow the following steps 1. The decimal fraction is multiplied by 2. the integer part, which is noted i. e. either 0 or 1 2. The fractional part of the previous product is multiplied by 2. 3. Repeat the first step until the fraction repeats or terminates. 4. The integer part which is obtained as a result forms a string of 0 s and 1 s which becomes the binary equivalent of the decimal fraction.

4. to obtain the binary number of the equivalent fractional, you need to consider

4. to obtain the binary number of the equivalent fractional, you need to consider the integer part from top to bottom.

� 167 � 0. 875 � 21. 625

� 167 � 0. 875 � 21. 625

� To convert a binary number to a decimal number, perform the following steps.

� To convert a binary number to a decimal number, perform the following steps. 1. Start with the rightmost digit and multiply that digit with 20. Here 2 represents the base of the number system and 0 represents the digit position, which is the rightmost digit whose position always starts with 0. 2. Continue working from right to left, and multiply each digit with an increasing power of 2 3. Repeat step 2 until all the digits have been multiplied 4. Add the result of each worked power of 2 for a final answer

� Fractional binary number can converted to decimal number in the same manner but

� Fractional binary number can converted to decimal number in the same manner but �The exponent are powers of two with negative values for digits on the right side of the binary point.

� 1001110 � 0. 10111

� 1001110 � 0. 10111

� Binary Addition � Binary Subtraction � Binary Division

� Binary Addition � Binary Subtraction � Binary Division

� Basic 1. four rules of addition First, we apply Rule 4 to find

� Basic 1. four rules of addition First, we apply Rule 4 to find the sum of the first two 1 s. 1 + 1 10 �

2. 3. � Next, we take the previous result of 102 and add the

2. 3. � Next, we take the previous result of 102 and add the final 1 to it. Notice that we use Rule 2 (0 + 1 = 1) to find the answer to the first column, We use Rule 3 (1 + 0 = 1) to find the answer to the second column. 10 + 1 11

4. � Now we have derived another rule for binary arithmetic. The sum of

4. � Now we have derived another rule for binary arithmetic. The sum of three 1 s in binary is 112. 1 1 + 1 11

� Add 1112, 11012, and 11102

� Add 1112, 11012, and 11102

�Addition is same as addition of binary integers, we need to take care of

�Addition is same as addition of binary integers, we need to take care of radix point while adding fractional part. � Example ◦ how to add the binary numbers 110. 012 and 1. 0112 1. First, we align the two numbers so that the radix point of each number is located in the same column. 110. 01 + 1. 011 2. Next, we fill in the blank spaces with 0 s and add the two numbers together. 110. 010 + 001. 011

3. 4. The first column adds to 1. 110. 010 + 001. 011 1

3. 4. The first column adds to 1. 110. 010 + 001. 011 1 The second column adds to 102, so we write a 0 below it and carry a 1 to the next column 1 110. 010 + 001. 011 01

5. 4. All of the remaining columns add to 1, so we write 1

5. 4. All of the remaining columns add to 1, so we write 1 below them. 1 110. 010 + 001. 011 111. 101 This gives us a final answer of 111. 1012.

� Add � 10. 101+1. 111

� Add � 10. 101+1. 111

2(10) 30 -6 24 The basic rules for binary subtraction are Consider 102. the

2(10) 30 -6 24 The basic rules for binary subtraction are Consider 102. the problem of subtracting 12 from

� To compute the first column, we need to borrow a 1 from the

� To compute the first column, we need to borrow a 1 from the next column. � Recall that two 1 s generated a carry in addition. � If we reverse this process, we can borrow a 1 from the second column. Once we borrow from the second column, we cross out the 1 and write 0 above it to show this column is now empty. 10 -1

�After cleaning up our work, we can see that the first column of our

�After cleaning up our work, we can see that the first column of our answer is identical to Rule 4. � Since we must borrow a 1 from the next column, 0 - 1 = 1. 10 - 1 1

� Subtract � 101101 − 100111 � 1011011 − 10010 � 1000101 − 101100

� Subtract � 101101 − 100111 � 1011011 − 10010 � 1000101 − 101100 � 100010110 − 1111010 � 1011. 101 -11. 011 �When the binary fraction 11101 is subtracted from the binary fraction 101101. 101 what is the correct result?

� Binary multiplication uses the same technique as decimal multiplication. � Binary multiplication is

� Binary multiplication uses the same technique as decimal multiplication. � Binary multiplication is much easier because each digit we multiply by is either zero or one. � Example 1102 multiplicand 10 2 multiplier � multiplying 1102 by 102 1. First, we note that 1102 is our multiplicand 102 is our multiplier.

2. 3. We begin by multiplying 1102 by the rightmost digit of our multiplier

2. 3. We begin by multiplying 1102 by the rightmost digit of our multiplier which is 0. Any number times zero is zero, so we just write zeros below. 110 x 10 000 Now we multiply the multiplicand by the next digit of our multiplier which is 1. To perform this multiplication, we just need to copy the multiplicand shift it one column to the left as we do in decimal multiplication.

110 x 10 000 110 4. Now we add our results together. The product

110 x 10 000 110 4. Now we add our results together. The product of our multiplication is 11002 110 x 10 000 1100

1. 2. 3. Ignore radix point, do not align them Multiply numbers as whole

1. 2. 3. Ignore radix point, do not align them Multiply numbers as whole numbers Starting from right of the product, separate as many places as there are in the two numbers together

10. 01*1. 01 1001 *101 ----1001 0000 1001 ------101101 Now put the radix point,

10. 01*1. 01 1001 *101 ----1001 0000 1001 ------101101 Now put the radix point, together binary fractions have four decimal places. starting from right separate the four decimal places 10. 1101

� When doing binary division, we need to remember some important rules: �When the

� When doing binary division, we need to remember some important rules: �When the remainder is greater than or equal to the divisor, write a 1 in the quotient and subtract. � When the remainder is less than the divisor, write a 0 in the quotient and add another digit from the dividend.

� If all the digits of the dividend have been considered and there is

� If all the digits of the dividend have been considered and there is still a remainder, mark a radix point in the dividend append a zero. �Remember that some fractions do not have an exact representation in binary, so not all division problems will terminate.

1. 2. 10|11 10 1 1. 10|11. 0 10 1 3.

1. 2. 10|11 10 1 1. 10|11. 0 10 1 3.

1. 10|11. 0 10 10 1. 1 10|11. 0 10 10 10 0

1. 10|11. 0 10 10 1. 1 10|11. 0 10 10 10 0

�Divisor must be a whole number, if it is not, then we will multiply

�Divisor must be a whole number, if it is not, then we will multiply it so that it becomes one. � Multiply the dividend by the same power � Example � 10. 1101/1. 01

� Divide 1000012 by 1102 � 10. 11101/11. 011

� Divide 1000012 by 1102 � 10. 11101/11. 011

� Digital computers respond to numbers, therefore data and numbers must be represented in

� Digital computers respond to numbers, therefore data and numbers must be represented in a numeral format. �The ON/OFF positions of electronic switches in a digital computers correspond to binary digits 0 or 1. �Inter-conversion of numbers from one number system into other becomes important for computation and data processing in digital computers.

� In digital computers very few rules are required to perform addition, subtraction, division

� In digital computers very few rules are required to perform addition, subtraction, division and multiplication.

Convert to decimal 10101001 i. iii. iv. 11100111 01101110 01101111

Convert to decimal 10101001 i. iii. iv. 11100111 01101110 01101111

� 45 i. ii. iv. v. 69 1066 99 1939 998

� 45 i. ii. iv. v. 69 1066 99 1939 998

DIVIDE 1) 11011001/1011 2) 101010111/11001 3) 1110101011. 110101/10110

DIVIDE 1) 11011001/1011 2) 101010111/11001 3) 1110101011. 110101/10110

Multiply 1) 1101 * 1101 2) 1011* 1001 3) 100011 * 1100011 4) 101010111

Multiply 1) 1101 * 1101 2) 1011* 1001 3) 100011 * 1100011 4) 101010111 * 11001 5) 1110101011. 110101 * 10110