Chapter 4 Binary Representation of Numbers After reading this chapter, you should be able to: convert a base- real number to its binary representation,. convert a binary number to an equivalent base- number. In everyday life, we use a number system with a base of. For example, look at the number 57.56. Each digit in 57.56 has a value of through 9 and has a place value. It can be written as 1 57.76 = + 5 + 7 + 7 + 6 In a binary system, we have a similar system where the base is made of only two digits and it is a base system. A number like (111 in base- represents the decimal number as 3 1 ( 111 = ((1 + + 1 + 1 + ( + + 1 + 1 = 11875 in the decimal system. To understand the binary system, we need to be able to convert binary numbers to decimal numbers and vice-versa. We have already seen an example of how binary numbers are converted to decimal numbers. Let us see how we can convert a decimal number to a binary number. For example take the decimal number 11875. First, look at the integer part: 1 Divide 11 by. This gives a quotient of 5 and a remainder of Since the remainder is 1, a = 1.. Divide the quotient 5 by. This gives a quotient of and a remainder of Since the remainder is 1, a = 1 1. 3. Divide the quotient by. This gives a quotient of 1 and a remainder of. Since the remainder is, a =. 4. Divide the quotient 1 by. This gives a quotient of and a remainder of Since the remainder is, a = 3 1. Since the quotient now is, the process is stopped. The above steps are summarized in Table 4.1
4. Chapter 4 Table 1 Converting a base- integer to binary representation. Quotient Remainder 11/ 5 1 = a 5/ 1= a1 / 1 = a 1/ 1 = a3 (11 = ( a3aa1a = (11 For any integer, the algorithm for finding the binary equivalent is given in the flow chart on the next page. Now let us look at the decimal part, that is,.1875. Multiply.1875 by. This gives.375. The number before the decimal is and the number after the decimal is.375. Since the number before the decimal is, a =.. Multiply the number after the decimal, that is,.375 by. This gives.75. The number before the decimal is and the number after the decimal is.75. Since the number before the decimal is, a =. 3. Multiply the number after the decimal, that is,.75 by. This gives 5. The number before the decimal is 1 and the number after the decimal is.5. Since the number before the decimal is 1, a = 4. Multiply the number after the decimal, that is,.5 by. This gives. The number before the decimal is 1 and the number after the decimal is. Since the number before the decimal is 1, a = Since the number after the decimal is, the conversion is complete. The above steps are summarized in Table. Table. Converting a base- fraction to binary representation. Number Number after Number before decimal decimal.1875.375.375 = a.375.75.75 = a.75 5.5 1 = a.5. 1 = a
Binary Representation of Numbers 4.3 Start Input (N Integer N to be converted to binary format i = Divide N by to get quotient Q & remainder R i = i+1 a i = R No Is Q =? Yes n = i (N = (a n...a STOP
4.4 Chapter 4 (.1875 = ( a 1a aa = (.11 The algorithm for any fraction is given in a flowchart on the next page. Having calculated ( 11 = (11 and (.1875 = (.11, we have ( 11875 = (111. In the above example, when we were converting the fractional part of the number, we were left with after the decimal number and used that as a place to stop. In many cases, we are never left with a after the decimal number. For example, finding the binary equivalent of.3 is summarized in Table 3. Table 3. Converting a base- fraction to approximate binary representation. Number after Number before Number decimal decimal.3.6.6 = a.6. 1 = a..4.4 = a.4.8.8 = a.8 6.6 1 = a 5 As you can see the process will never end. In this case, the number can only be approximated in binary format, that is, (.3 ( a a aaa 5 = (.1 Q: But what is the mathematics behinds this process of converting a decimal number to binary format? A: Let z be the decimal number written as z = x. y where x is the integer part and y is the fractional part. We want to find the binary equivalent of x. we can write
Binary Representation of Numbers 4.5 Start Input (F Fraction F to be converted to binary format i = Multiply F by to get number before decimal, S and after decimal, T i = i a i = R No Is T =? Yes n = i (F = (a -1...a -n STOP
4.6 Chapter 4 x = a n n n + an 1 +... + a If we can now find a,...,a n in the above equation then ( x = ( anan.. a We now want to find the binary equivalent of y. we can write y = b + b +... b 1 + If we can now find b 1,..., b m in the above equation then ( y = ( b 1b... b m Let us look at this using the same example as before. m m Example 1 Convert (11875 to base. lution To convert (11 to base, what is the highest power of that is part of 1 That power is 3, as 3 = 8 to give 11 = 3 + 3 What is the highest power of that is part of 3. That power is 1, as 1 = to give 3 = 1 + 1 3 3 1 11 = + 3 = + + 1 What is the highest power of that is part of That power is, as = 1 to give 1 = 3 1 3 1 3 1 ( 11 = + + 1 = + + = 1 + + 1 + 1 = (11 To convert (.1875 to the base, we proceed as follows. What is the smallest negative power of that is less than or equal to.1875. That power is 3 as 3 =.15..1875 = +.65 What is the next smallest negative power of that is less than or equal to.65. That power is 4 as =. 65. 3.1875 = + (.1875 = +.65 = + = + + 1 + 1 = (.11 Since ( 11 = (11 and (.1875 = (.11 we get
Binary Representation of Numbers 4.7 ( 11875 = (111 Can you show this algebraically for any general number? Example Convert (13.875 to base. lution For (13, conversion to binary format is shown in Table 4. Table 4. Conversion of base- integer to binary format. Quotient Remainder 13/ 6 1 = a 6/ 3 = a1 3/ 1 1 = a 1/ 1 = a3 ( 13 = (11. Conversion of (.875 to binary format is shown in Table 5. Table 5. Converting a base- fraction to binary representation. Number Number after Number before decimal decimal.875 75.75 1 = a.75 5.5 1 = a.5. 1 = a (.875 = (.111 ( 13.875 = (1111 INTRODUCTION TO NUMERICAL METHODS Topic Binary representation of number Summary Textbook notes on binary representation of numbers Major General Engineering Authors Autar Kaw Date December 7, 8 Web Site http://numericalmethods.eng.usf.edu