Numbers represented using groups of bits (1s and 0s) are said to be BINARY NUMBERS. Binary numbers are said to be in base 2.

Size: px
Start display at page:

Download "Numbers represented using groups of bits (1s and 0s) are said to be BINARY NUMBERS. Binary numbers are said to be in base 2."

Transcription

1 DATA REPRESENTATION All data used by computers is in code form, based on the two digits 0 and 1. This is so, in order to reflect the two-state components of which these digital systems are made. Numbers represented using groups of bits (1s and 0s) are said to be BINARY NUMBERS. Binary numbers are said to be in base 2. Before we consider a number of different codes for storing numeric and character data, it is appropriate to recall some mathematical number system concepts that are a prerequisite for our discussion of data representation. The Denary System (RECALL) Let us first take a look at the denary system or the base-10 number system, which we are so accustomed to. The number 3768 is 3 thousand, 7 hundred and sixty eight: (3 x 1000) + (7 x 100) + (6 x 10) + (8 x 1) M.S.D L.S.D Note the weighting of each digit as we move to the left: or Thus we can write the above number as: (3 x 10 3 ) + (7 x 10 2 ) + (6 x 10 1 )+ (8 x 10 0 ) Remarks: Any number to the power of zero is one The weight to each digit is technically known as the place (positional) value since the weight or value of the digit depends on its place (position) within the number. Hence the place value table of the denary system is Cutajar&Cutajar2003 1

2 Since the base (or radix) is ten, the positional weight is to the power of 10. There are 10 distinct digits to this system. Digits in a base 10 system are: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 Consider the decimal number : = = (3 x 1000) + (5 x 100) + (6 x 10) + (7 x 1) + (4 x 1/10) + (5 x 1/100) + (2 x 1/1000) = (3 x 10 3 ) + (5 x 10 2 )+ (6 x 10 1 )+ (7 x 10 0 )+ (4 x 10 1 )+ (5 x 10 2 ) + (2 x 10 3) Note that the decimal point separates the whole part of the number (on the left hand side) from the fractional part of the number (the right hand side). One can add as many 0 s to the left of the number without in any way changing the number ex = One can SHIFT the number LEFT by inserting a 0 to the RIGHT of the number. Shifting the number left multiplies it by 10 (the base). Thus = 10*4206. One can SHIFT the number RIGHT by one position to DIVIDE it by 10. The LSD which DROPS OFF the right end is the remainder after dividing by 10. Thus 4206 /10 = 420 r 6. Unless the number base is clearly understood, a given number must have its base specified as a subscript at the end of the number, say The basic concepts of number systems recalled in this section will now be used to introduce you to other number systems that are more convenient for use in a digital environment. The Binary System Number representation in a digital system can take only two values 1 or 0 because of the physical characteristics of the components of which it is built (as already pointed out). A brief explanation of actual physical representation of 0 and 1 values may be found in appendix A. In the binary system: The base (radix) of the binary system is 2. Hence, there are two distinct digits: 0 and 1. Cutajar&Cutajar2003 2

3 A single binary digit is called a bit BInary digit = BIT. Place Value table (Remember concept of place value): /2 1/4 1/8 1/16 Integral numbers Fractional numbers Example 1. : Binary point The number would represent: i.e. (1 x 2 3 ) + (1 x 2 2 ) + (0 x 2 1 ) + (1 x 2 0 ) + (0 x 2 1 ) + (1 x 2 2 ) (1 x 8) + (1 x 4) + (0 x 2) + (1 x 1) + (0 x ½) + (1 x ¼) = = Conversion: binary decimal Example 1: = (1 х 2 3 )+ (1 х 2 2 ) + (1 х 2 1 ) + (1 х 2 0 ) = = Example 2: = (1 х 2-1 )+ (0 х 2-2 ) + (1 х 2-3 ) + (1 х 2-4 ) = = Example 3: = (1 х 2 1 )+ (0 х 2-1 ) + (1 х 2-2 ) + (1 х 2-3 ) = = Exercise 1: Convert the following binary numbers to decimal: i (Ans ) Cutajar&Cutajar2003 3

4 ii (Ans ) iii (Ans ) iv (Ans ) Conversion: decimal binary i) by inspection ii) systematic method: repeated division/multiplication In converting from decimal to binary, the integer part and the fractional part of the number are processed separately. For the integer part, division by 2 is repeated on the quotient only until the quotient becomes zero and the equivalent binary integer number part is obtained by taking the remainders. For the fractional part, multiplication by 2 is repeated on the fractional part until the fractional part becomes zero. For each successive multiplication, only the fractional part of the previous result is multiplied by the base 2. The equivalent binary fraction is obtained by taking the whole part of each intermediate multiplication result. After a number of multiplications the fractional part may not have become zero. Hence, the process is often terminated when the desired number of digits is obtained. Example 1: (by inspection) = = (1 х 2 3 ) +(1 х 2 2 ) + (0 х 2 1 ) + (0 х 2 0 ) = Example 2: (by inspection) = = (1 х 2-1 ) +(1 х 2-2 ) + (0 х 2-3 ) = Example 3: (by inspection) = = (1 х 2 4 ) +(0 х 2 3 ) + (0 х 2 2 ) + (0 х 2 1 ) + (1 х 2 0 ) +(1 х 2-1 ) + (1 х 2-2 ) = Exercise 2: Using inspection, show that = Cutajar&Cutajar2003 4

5 Example 4: Convert to binary using repeated multiplication х 2 = х 2 = х 2 = х 2 = = Example 5: Converting integral part using inspection: 13 = = When converting the fractional part, if inspection seems difficult, use systematic method. Converting fractional part using repeated multiplication: х 2 = х 2 = х 2 = х 2 = = = Example 6: Converting the integer part into binary using repeated division: Note that integral part may always be easily converted using inspection. This example is only worked out using inspection for the sake of completeness Remainder 1 gives any odd 2 0 (1) when grouping in 2s 2 36 Remainder 0 gives any odd 2 1 (2s) when grouping in 4s 2 18 Remainder 0 gives any odd 2 (4s) when grouping in 8s 2 9 Remainder 0 gives any odd 2 3 (8) when grouping in 16s 2 4 Remainder 1 gives any odd 2 4 (16) when grouping in 32s 2 2 Remainder 0 gives any odd 2 5 (32) when grouping in 64s 2 1 Remainder 0 gives any odd 2 6 (64) when grouping in 128s 0 Remainder 1 gives any odd 2 7 (128) when grouping in 256s = (write remainders ) Cutajar&Cutajar2003 5

6 = There was 1/2 in the original number ( 2) = There was 1/4 in the original number ( 2 2) = There was 1/8 in the original number ( 2 2 2) = There was 1/16 in the original number ( ) = There was 1/32 in the original number ( ) = There was 1/64 in the original number ( ) = There was 1/128 in the original number ( ) = There was 1/256 in the original number ( ) = There was 1/512 in the original number ( ) Converting to binary using repeated multiplication: Note the recurrence! = = Exercise 3: Convert the following decimal numbers to binary: i (Ans ) ii (Ans ) iii (Ans ) iv (Ans ) Hexadecimal System Imagine having to remember and handle long strings of bits such as In computing, it is at times necessary to inspect and manipulate bit strings, for example when inspecting memory contents. In order to make it easier to manipulate binary strings it is usual to use a notation that could be easily translated to binary when required and yet more concise. The hexadecimal system (hex) matches such criteria and often, binary strings are expressed in hex. The base of the hexadecimal system is 16. Hence 16 digit symbols are required: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Thus the hexadecimal digits are: Hex A B C D E F Dec Bin Place Value table of hexadecimal system: Cutajar&Cutajar2003 6

7 /16 1/256 1/4096 Integer part Fractional part Hexadecimal point Conversion: Hexadecimal Decimal Example 1: Convert A0B 16 to decimal: A0B 16 = (A х 16 2 ) + (0 х 16 1 ) + (B х 16 0 ) = (102 х 56) + (0 х 16) + (11 х 1) = = Example 2: Convert 4CF.CD 16 to decimal. 4CF.CD 16 = (4 х 16 2 ) + (C х 16 1 ) + (F х 16 0 ) + (C х 16-1 ) + (D х 16-2 ) = (4 х 256) + (12 х 16) + (15 х 1) + (12 х 1/16) + (13 х 1/256) = Exercise 4: Convert the following Hexadecimal numbers to decimal: i. 26C (Ans ) ii. 3A4.0C 16 (Ans ) Conversion decimal hexadecimal To convert from decimal to hexadecimal the same procedure as for binary numbers is adopted, but this time instead of 2 we use 16, as the hex system is base 16. Conversion again requires the processing of the integer and fractional parts separately. For the integer part, division by 16 is repeated on the quotient until the quotient becomes zero and the binary number is taken from the remainders of the successive divisions. For the fractional part, multiplication by 16 is repeated on the fractional part only, taking the integer part of the successive multiplications as the result. This process is repeated until either the fractional part becomes zero, or when the desired significant figures are obtained. Cutajar&Cutajar2003 7

8 Example 1: Convert to hexadecimal By repeated division: Rem Rem 7 Rem = Example 2: Convert to hexadecimal. By repeated multiplication: * 16 = * 16 = * 16 = * 16 = E Exercise 5: = 0.213E 16 Convert the following decimal numbers to Hexadecimal: i (Ans. 44F.3 16 ) ii (Ans. AE.9 16 ) iii (Ans. D ) Conversion binary hexadecimal Note the relationship between binary system and hexadecimal system: binary /2 1/4 1/8 1/16 1/32 hex /16 Consider the binary number Converting from binary to hexadecimal: We first divide the number into groups of four starting from the binary point. Add (insignificant) 0s to make to the left and right of the number if necessary: Cutajar&Cutajar2003 8

9 Convert each group of four binary digits to a single hex digit: Remember: Hex A B C D E F Bin Hence, Becomes 6 A 9. B 4 Converting from hexadecimal to binary: Substitute each hex digit into its 4-bit binary equivalent. Hence, D9 16 = Exercise 6: Convert the following Hexadecimal numbers to binary: i. AFC2 16 (Ans. : ) ii. 136C 16 (Ans ) iii. 7FA 16 (Ans ) iv. FF60 16 (Ans ) Octal System The base of the octal system is 8. Hence 8 digit symbols are required: 0, 1, 2, 3, 4, 5, 6, 7 Place Value table for octal system: /8 1/64 1/512 1/4096 Integer part Fractional part Octal point Conversion: octal decimal Example 1: = (1х8 2 ) + (0 х 8 1 ) + (1 х 8 0 ) = = 65 Cutajar&Cutajar2003 9

10 Example 2: = (4 х 8 3 ) + (5 х 8 2 ) + (7 х 8 1 ) + (2 х 8 0 ) = = Example 3: = (4 х 8 1 ) + (5 х 8 0 ) + (7 х 8-1 ) = /8 = Exercise 7: Convert the following octal numbers to decimal: i (Ans ) ii (Ans ) iii (Ans ) Conversion: decimal octal i) by inspection ii) by repeated division/multiplication Example 1: = = 12 8 Example 2: Convert to octal by repeated division Rem Rem Rem 3 = Rem = Example 3: Convert by repeated multiplication * 8 = * 8 = * 8 = * 8 = * 8 = * 8 = Cutajar&Cutajar

11 * 8 = * 8 = * 8 = * 8 = = Example 4: * 8 = Rem Rem 3 = Rem = = Exercise 8: = Convert the following decimal numbers to octal: i (Ans ) ii (Ans ) iii (Ans ) Conversion: Binary Octal Binary digits Octal digits Consider the binary number Converting from binary to octal: We first divide the number into groups of three starting from the binary point and adding insignificant 0s to the left and right of the number if necessary Converting each group to a single digit becomes Converting from octal to binary: Substitute each octal digit with the 3-bit binary equivalent. Hence, = Cutajar&Cutajar

12 Exercise 9: Convert the following octal numbers to binary: i (Ans ) ii (Ans ) iii (Ans ) iv (Ans ) Remarks: To convert from octal to hex: octal binary hex To convert from hex to octal: hex binary octal Conversion Summary Digit(n) x 16 n and add Continuous division / multiplication by 16 Decimal 10 Digit(n) x 8 n and add Continuous division / multiplication by 8 Digit(n) x 2 n and add Continuous division / multiplication by 2 Hex 16 In groups of 4 and convert each group Convert each digit to 4 bit binary Binary 2 In groups of 3 and convert each group Convert each digit to 3 bit binary Octal 8 Cutajar&Cutajar

13 Binary Quantities. 1 Binary digit is called a bit and can have either a value of zero or 1 4 bits are called a nibble. 8 bits are called a byte 16 bits are called a word 32 bits are called a double word (Dword) 64 bits are called a quad word (Qword) 1024 bytes are called 1 Kilo Byte (1K or 1Kb) 1024 x 1024 bytes = 1024 K bytes are called 1 Mega Byte (1M or 1 Mb) 1024 x 1024 x 1024 bytes = 1024 Mbytes = 1 Giga Byte (1G or 1 Gb) 1024 x 1024 x 1024 x 1024 bytes = 1024 Gbytes = 1 Tera Byte b b b b b b b b b Most Significant Bit (M.S.B) the bit with the highest weight Least Significant Bit (L.S.B) the bit with the least weight Value ranges for unsigned numbers. A single bit can represent one of TWO POSSIBLE values. Using one bit we can only represent any data that can have only two possible values, ex. 1 and 0,True and False, Male and Female. Suppose our data are seasons. Clearly one bit is not enough, because a single bit can represent only 2 things, and there are four seasons. So one must use more than one bit. Suppose one uses 2 bits. The latter give four possible PATTERNS which can be used to represent the four different seasons. The seasons are in human readable form. Inside the computer they will be represented in MACHINE READABLE FORM as a code of 2 signals (2 bits) Using bits to represent positive whole numbers (unsigned integers) Consider the following: - With a single bit just 2 values can be represented 0 or 1 - With 2 bits, 4 values can be represented 00, 01, 10 or 11 (0, 1, 2, 3) - With 3 bits, 8 values can be represented 000, 001, 010, 011, 100, 101, 110 or 111 (0, 1, 2, 3, 4, 5, 6, 7) Cutajar&Cutajar

14 - By analyzing the above sequence one can notice that given n bits, the values that can be represented are 2 n values in number, ranging from 0 to (2 n 1). - Verification with 4 bits: One can represent 2 4 values = 16. These values range from 0 to (2 4 1) = 0 to 15: 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, Remark: Note that unlike standard science values where 1 K represents exactly 1,000 and 1 M exactly 1,000,000, in computing these quantities are different. - 1 Kilo = 2 10 = 1,024-1 Mega = 2 10 x 2 10 = 2 20 = 1,024x 1,024 = 1,048,576-1 Giga = 2 10 x 2 10 x 2 10 = 2 30 = 1024x1024x1024 = x 10 9 Representations in binary. Let us now consider how many bits are needed to represent a certain number of values in binary. We derived that n bits can represent 2 n values. Let us call these X values. Thus, X = 2 n Taking logs 10 on both sides Hence log 10 (X) = log 10 (2 n ) log 10 (X) = n * log 10 (2) n = log 10 (X) log 10 (2) n = Log 10 (x) Log 10 (2) Example 1: (a) How many numbers can be expressed using 16 bits? (b) What is the range of values that can be represented using 16 bits? (a) There are 2 n distinct numbers that can be expressed using n bits Given n = 16 Cutajar&Cutajar

15 2 16 = numbers can be expressed. (b) The range of these numbers is from 0 to 2 n -1 Given n = 16 range: 0 to i.e. 0 to Example 2: How many bits are needed to be able to express numbers Given, n = Log 10 (X) / Log 10 (2) where X = number of distinct values needed n = number of bits hence, n = log 10 (32768) / log 10 (2) = / bits Remark: In general, the result is not an integer number but n must be an integer number. (number of bits!!). Thus if the result is not a whole number we take the nearest whole number higher than the result. Example3: How many bits are required to be able to represent 9 numbers: n = log 10 (X) / log 10 (2) but X = 9 hence, n = log 10 (9) / log 10 (2) = / = is rounded to 4 bits (upper bound). In fact with just 3 bits one can represent only from 0 to 7 as seen earlier! Shortcut to avoid logs. It is quite easy to remember the first 2 n numbers where n = 1,2,.. 9, 10,20,30. N n K 1 1 Cutajar&Cutajar

16 M G Using the property that 2 (x+y) = 2 x. 2 y We can convert the number into K, M or G and calculate accordingly. Example 1: Required, number of bits needed to represent 256 numbers: Directly from table, we can see that the number of bits is 8. Example 2: Required, the number of bits needed to represent numbers: / 1024 = 128 K hence, = From the table we see that 128 = 2 7 Hence, = = 2 17 Thus we need 17 bits to represent numbers. Arithmetic operations in different number systems. All four arithmetic operations can be done directly without converting to decimal. Let us consider the following operations in different number systems: addition subtraction multiplication division Cutajar&Cutajar

17 1. Addition Addition in binary. Carry every group of two! Example 1: Remember to align binary point! Carry (Group of 2) Let us consider all possible combinations that can occur when adding two binary digits: Carry brought forward Digit A Digit B Sum Carry carried forward Addition in octal. Carry every group of eight! Example 1: Remember to align octal point. Carry (group of 8) Cutajar&Cutajar

18 Addition in hex. Carry every group of sixteen! Example 1: A18 + F7 Remember to align hexadecimal point. 1 A F 7 B 0 F Exercise 10: Add the following binary numbers: i (Ans ) ii (Ans ) 2. Subtraction. Subtraction in binary. Borrow a group of 2! Borrow (group of 2) Example 1: (2) (1) (2) = Subtraction in octal. Borrow a group of 8! Example 1: (7) (8) Cutajar&Cutajar

19 Subtraction in hex. Borrow a group of 16! Example 1: 421 A6 (16) (16) A B Exercise 11: Subtract the following binary numbers: i (Ans ) ii (Ans ) iii (Ans ) iv (Ans ) 3. Multiplication. Remember the long multiplication technique used in decimal multiplication: We multiply the multiplicand with each digit of the multiplier in turn; then sum up these partial products to produce the result. Multiplication in binary. In binary this process is much easier since the digits of the multiplier can only be either a 0 or 1. Thus the partial products are either 0 or equal to the multiplier with added right-trailing zeros if necessary. Hence, - if the bit is 1 then the multiplicand is copied beneath the bit in question. - if the bit is 0 then 0 s are entered in that position x (9) (11) Partial products (99) product Cutajar&Cutajar

20 The 4-bit multiplication aside can have at most an 8-bit result Exercise 12: Multiply the following binary numbers: i * (Ans ) ii * (Ans ) iii * (Ans ) iv * 10 2 * (Ans ) 4. Division. When performing long division on decimal numbers, we perform the following actions: Try dividing the first digit of the dividend by the divisor to see if it fits. If it fits, then we find out by how much it fits, write this in the quotient and then subtract the divisor multiplied by how much it fits from the considered part of the dividend. We bring another digit of the dividend and repeat the same procedure until no further digits remain in the dividend. The remaining number is the remainder of the division. Divisor Quotient Dividend Remainder Cutajar&Cutajar

21 Division in binary. In binary, this process is easier since it either doesn t fit or just fit once. Performing the binary long division below: Try dividing 1 by 1101 and it doesn t fit so we successively try dividing 10, 100 and 1000 by 1101 without success. We then find 1101 fits in so we write 1 in the quotient and subtract 1101 from which leaves 100. We bring another digit of the dividend and repeat the same procedure until no further digits remain in the dividend. The remaining number is the remainder of the division Quotient Divisor Dividend Remainder 1 Exercise 13: Divide the following binary numbers: i / 10 2 (Ans ) ii / (Ans ) iii / (Ans R 11 2 ) iv / (Ans R ) Cutajar&Cutajar

22 Numeric Codes. Unsigned number representation. Binary Code for unsigned numbers. In order to represent unsigned numbers, code based on binary number system is used. Given an 8-bit register to store unsigned binary integer numbers: Or binary point binary point. Example 1: Represents = In general, given an n-bit register, the value of each register bit would be: 2 n 2 n Given an n-bit register to store unsigned binary fractional numbers. Binary point n+2 2 -n+1 2 -n. Example1: Given that the 8-bit register stores an unsigned fraction: The decimal fraction stored is: 0 + 1/4 + 1/ / / = Cutajar&Cutajar

23 Binary Coded Decimal Code (BCD code) BCD code is usually used to store unsigned numbers. Given a denary number, each (decimal) digit is coded separately in binary. Since there are 10 decimal digits, a minimum of 4 bits is required to store each of these ten digits. Decimal digit Binary equivalent Example 1: Represent in BCD code. From the above table, 5 is replaced by is replaced by is replaced by in BCD code Because the 4-bit binary equivalent number is being used to code each digit, this form of BCD code is generally known as the BCD 8421-weighted code. Exercise 14: Represent in BCD code. (Ans in BCD code) Remarks: i) There exist other BCD codes with different weightings say BCD 2421-weighted code. Note that with these 2421 weights you may still obtain the required ten decimal digits. ii) Since four bits are the minimum number of bits possible to code each of the ten decimal digits, we speak of a PACKED BCD. Two BCD coded digits are packed in a single byte (8 bits). Cutajar&Cutajar

24 iii) A number to be coded in BCD must be in decimal form. If not, we must first convert the number in question into decimal and then code (each decimal digit) in BCD code. iv) Whereas conversion to/from BCD code to denary is simple (even in implementation circuitry) [ADVANTAGE], arithmetic using BCD coded operands is quite complex [DISADVANTAGE]. Hence BCD codes are used in (commercial) applications where there is the likelihood that a large input/output is required and only simple calculations are involved. (Ex. advertisement running displays, pocket calculators). Also not so efficient since 6 representations are not being used (wasted). How is the unary sign (±) represented in actual computers? The numeric codes to be now discussed will provide methods for representing signed numbers. Signed number representation. Two numeric codes used to represent signed numbers in a computer system are: Sign & Magnitude code Two s Complement code Sign and Magnitude Code. Using this notation, the sign and the magnitude of the number are coded separately. Hence a bit, called the sign bit is used to code the sign of the number, while a number of bits are used to represent the magnitude of the number. Consider, + 17 sign magnitude Representing the sign of the number and its magnitude separately. Magnitude (absolute value) of the number Sign Bit 0: Positive Number 1: Negative Number Cutajar&Cutajar

25 Example 1: Represent + 17 in an 8-bit register using sign-and-magnitude code. Hence also represent 17. Appended zeroes Sign bit Binary equivalent Representing -17 using 8 bits: Note that the code for 17 is the same as that for +17 except for the sign bit (since magnitude is the same). Example 2: Represent in an 8-bit register using S-M code (13/32) = 1/4 + 1/8 + 1/32 Sign. bit 1/2 1/4 1/8 1/16 1/32 1/64 1/ : and, : Remarks: i) If 8 bits are available to represent signed numbers, then the range of numbers that can be represented is: ii) i.e. [-127, +127] Biggest Biggest +ve magnitude -ve possible number number In general, the range of an n-bit register is: [-2 n-1 + 1, +2 n-1 1] and is symmetric. Cutajar&Cutajar

26 iii) Note that there are TWO representations of 0, i.e. there is: The positive zero: - say, on five bits including sign The negative zero: - say, on five bits including sign iv) Arithmetic operations cannot be performed directly on a negative number represented in Sign and Magnitude. Example: Consider the addition of +5 and 3 assuming a 5-bit register. This is evidently a wrong answer Exercise 15: 1. Using an 8-bit register storing integers represent the following in sign and magnitude format: i. 4 and -4 (Ans , ) ii. 13 and -13 (Ans , ) iii. 30 and -30 (Ans , ) iv. 123 and -123 (Ans , ) 2. Using an 8-bit register storing fractions represent the following in sign and magnitude format: i and (Ans , ) ii and (Ans , ) iii and (Ans , ) Two s Complement Code. Consider an 8-bit register: MSB represents negative quantity Normal binary (positive) place values Cutajar&Cutajar

27 Decimal Number Μ ( ): ( ): ( ): Two s complement code Remarks: i) If 8 bits are available to represent signed numbers, then the range of numbers that can be represented is: i.e. [-128, +127] In general, the range of an n-bit register is: [-2 n-1, + 2 n-1 1] and is not symmetric. There is always one more negative then positive numbers. ii) For positive numbers two s complement code yields the same code as for the sign-and-magnitude representation. iii) Quick method to represent negative numbers in two s complement code: Step 1: Convert number into binary using the required number of bits Step 2: Change all 0s 1s and 1s 0s Step 3: Add 1 (to LSB) Example 1: Represent -126 in an 8-bit register using two s complement code. (1) +126: (2) (3) Note that this method also converts a number in twos complement negative form to positive form. (Algorithm toggles representation by successive applications) Cutajar&Cutajar

28 Example 2: (1) (2) 1 + (3) [Fastest informal method: starting from the LSB copy any trailing 1s (up to the first 1 from the right) then change the rest of the digits from 1 0 and from 0 1.] Example 3: Represent in an 8-bit register using two s complement code. -1 1/2 1/4 1/8 1/16 1/32 1/64 1/ (13/32) = 1/4 + 1/8 + 1/ : and, : iv) There is one representation of 0 i.e. The positive zero on five bits including sign (Adding 1 to results again in ) v) Arithmetic operations can be performed directly on a negative number represented in twos complement Example 1: Consider the addition of +5 and 3 on 5 bits including sign. The carry out from the sign bit is simply ignored here The result is directly correct Cutajar&Cutajar

29 Example 2: Perform the following subtraction using two s complement: 29 7 Rem: 29 7 = 29 + (-7) Using an 8 bit register: 29 : : adding: (ignore carry) required result ( +22) Example 3: Perform the following subtraction using two s complement: Rem: = 29 + (-31) Using an 8 bit register: 29 : : adding: negative result no carry required result (-2 10 ) When adding numbers held in two s complement one uses the same binary addition rules but ignores the carry out. Addition of numbers with a different sign never produces an overflow. The latter can only occur when adding numbers having the same sign (both +ve or both ve) and the result has a sign different from the signs of the addends. When addition overflow occurs the carries into and out of the sign bit are different. vi) A matter that is confusing when interpreting signed binary numbers is the interpretation of negative numbers. One must be careful that: If the number starts with 0 (i.e. sign bit = 0) it is positive and can be read directly. If the number starts with 1 (i.e. sign bit = 1) it cannot be read directly if not in S&M. It must be reconverted to positive to be able to read it in binary, and then add the negative sign [An alternative is from first principles by noting the place value headings of each bit. Remember that the MSB is negative whereas the rest of the bits are positive.] Cutajar&Cutajar

30 Exercise 16: 1. Using an 8-bit register storing integers represent the following in two s complement format: i. 22 and -22 (Ans , ) ii. 120 and -120 (Ans , ) iii. 51 and -51 (Ans , ) 2. Evaluate the following binary numbers stored in two s complement format: i (Ans ) ii (Ans ) iii (Ans ) 3. Perform the following subtractions using two s complement 8-bit registers. Detect also whether overflow occurs in anywhere: i (Ans ) ii (Ans ) iii (Ans ) iv (Ans Overflow) v (Ans Overflow) Numeric Data Representation Fixed-point representation. In the methods of coding described above sign and magnitude code, twos complement code both for integers and fractions, the binary point has been in a fixed position For integers at the extreme right of the register For fractions after the MSB This type of number representation is called FIXED-POINT BINARY REPRESENTATION. Fixed-point binary representations are used to represent integer numbers in computers. Though the representation is to full accuracy, however the range of values that may be represented in a given register is very limited. Assuming twos complement code: Given an 8-bit register, range [-128, +127] For a 16-bit register, range [-32,768, +32,767] This is not sufficient for many applications! Cutajar&Cutajar

31 Floating-point representation. Floating point representation extends the range of numbers that can be represented by a given number of bits. As in pocket calculators, when the numbers get very large or very small (fractions) the display turns in exponent form and for example 9,000,000,000 would be shown as 9 x 10 9 or would be displayed as 9 x 10-9 Floating point representation is similar in nature to this scientific notation (standard form of number representation) Assuming decimal numbers: = * 10 3 = * 10 2 = = * 10-1 = * 10-2 = Floating point representation uses the same principle, but obviously in base 2. Say, = * 2 4 Fractional part: Mantissa exponent Consider a register used to represent floating point numbers; some bits are used to represent the mantissa, while the rest of the bits are used to represent the exponent. Consider a 12-bit register in which 8 bits are used to represent the fractional part of the floating-point number and 4 bits are used to represent the exponent part of the number. 8 bit 4 bit MANTISSA EXPONENT Using this format of the 12 bit register: = * Cutajar&Cutajar

32 Example 1: Represent as a floating point number using a 12 bit register where the first 8 bits are used to code the mantissa in twos complement and the remaining bits represent the exponent in twos complement code. Step 1: convert to binary = Step 2: represent the resulting binary number in standard form 100 (4) i.e = * 2 Step 3: write mantissa and exponent using available bits i.e Step 4: if mantissa /exponent is negative, complement the relevant group of bits (not applicable) = Example 2: Using the same register format as in example 1, represent Steps remain the same as in example 1. Step 4: given = Complement ve mantissa +ve exponent remains unchanged = Example 3: Using the above 12-bit register format, represent in floating point = (+5) = * 2 Note: Mantissa: -ve Exponent: +ve Cutajar&Cutajar

33 Remarks: In the above examples, the mantissa is a fraction between 1/2 and 1. In fact if you follow the above steps, represent binary number in standard form ensures that (but for some exceptional cases) the fraction is always between 1/2 and 1. When the mantissa of a floating-point number is expressed as a fraction between 1/2 and 1, the floating-point number representation is said to be NORMALISED. Normalisation ensures (i) single representation of a number : +1 - normalised : : +1 not normalised (ii) the maximum number of bits are available to store the fractional part of the number Consider (1011) not normalised 4 bits lost (1) normalised 1 bit lost Exercise 17: 1. Represent the following as normalised floating point numbers using a 16-bit register where the first 10 bits are used to code the mantissa in twos complement and the remaining bits represent the exponent in twos complement code. i and (Ans , ) ii and (Ans , ) iii. 30 (Ans ) iv. 123 (Ans ) 2. Evaluate the following, given that the first 5-bits are used to store the exponent and the rest store the mantissa both in two s complement form. i (Ans ) ii (Ans. 2.17) iii (Ans ) Cutajar&Cutajar

34 Also mention floating-point representation using sign and magnitude. Example 1: Represent as a floating point number using a 12-bit register where the first 8 bits are used to code the mantissa in sign and magnitude and the remaining bits represent the exponent in twos complement code. Step 1: convert to binary = Step 2: represent the resulting binary number in standard form 100 (4) i.e = * 2 Step 3: write mantissa and exponent using available bits i.e For positive numbers steps are the same as when the mantissa stored numbers in twos complement format. Example 2: Using the same register format as in example 1, represent Steps remain the same as in example 1. Step 4: given = Sign bit changes to a 1 ( ve ) +ve exponent remains unchanged = Example 3: Using the above 12-bit register format, represent in floating point = (+5) = * 2 Note: Mantissa: -ve Exponent: +ve Cutajar&Cutajar

35 Same exercise as 17 Question 1: Represent the following as normalised floating point numbers using a 16-bit register where the first 10 bits are used to code the mantissa in sign and magnitude and the remaining bits represent the exponent in twos complement code. i and (Ans , ) ii and (Ans , ) iii. 30 (Ans ) iv. 123 (Ans ) Range of floating point number representation. Assume a 12-bit register with an 8-bit mantissa and 4-bit exponent, both in twos complement code /2 1/4 1/8 1/16 1/32 1/64 1/ Range: (Remember normalisation!) - Minimum negative Maximum negative 0 Minimum positive Maximum positive + Floating-point binary bit pattern for maximum magnitude positive number: Binary point to extreme right for largest positive number Largest positive fraction possible In decimal: (1 1/128) * 2 7 = +127 Floating-point binary bit pattern for minimum magnitude positive number: Binary point to extreme left for smallest positive number Cutajar&Cutajar

36 In decimal: (+0.5) * 2-8 = Floating-point binary bit pattern for minimum magnitude negative number: Binary point to extreme left for smallest negative number Smallest negative fraction possible In decimal: - (1/2 + 1/128) * 2-8 = Floating-point binary bit pattern for maximum magnitude negative number: Binary point to extreme right for largest magnitude negative number Largest negative fraction possible In decimal: -(1) * 2 7 = -128 Range of 12-bit register in floating point format as described +127 above + is - [ -128, +127 ] Cutajar&Cutajar

37 Note that a small range around zero [ , ] is not represented. Exercise (in class): Show that the range of numbers in floating point, for a 16-bit register with a 10- bit twos complement mantissa and a 6-bit twos complement exponent is: [-( * 10 9 ), +(2.1433* 10 9 )]. Compare range of integers in a 16-bit register: [ , ] (Ans. Max +ve = , Min +ve = Min ve = , Max ve = Remarks: i) Note how the range of floating point representation explodes with the addition of just a few bits Range of 12-bit (8M/4E) register: [ -128, +127 ] Range of 16-bit (10M/6E) register: [-( * 10 9 ), +(2.1433* 10 9 )] ii) Given an n-bit register for representing floating point numbers: x-bit mantissa y-bit exponent Suppose that x bits are used to represent the mantissa and y bits are used to represent the exponent. Hence n = x + y If y is made large (hence x made small), you would be increasing the range of numbers that can be represented in floating point using the n-bit register but sacrificing on the precision. Likewise, if x is made large (hence y made small), you would be increasing the precision of the representation (since more bits are available to represent the mantissa) but losing on the range of numbers that may be represented by the register. iii) In floating point format, we have no representation of zero. In practice, the smallest positive number is used as a representation of zero. Any other result Cutajar&Cutajar

38 falling between the smallest magnitude positive number and the smallest magnitude negative number is represented by zero. Addition using twos complement floating point numbers. Assume a 12-bit register using an 8-bit mantissa and a 4-bit exponent. Method: i) If exponents of the two numbers are not the same, make the smaller exponent equal to the bigger exponent and shift binary point right accordingly. ii) Add the mantissas of the two numbers iii) If carry 1 to MSB move binary point 1 left and increment exponent by 1. Example 1: Consider no carry! Example 2: Consider carry Cutajar&Cutajar

39 Subtraction of floating point numbers using twos complement codes. Use the same algorithm as for addition. Remember we perform subtraction using twos complement of minuend (number being subtracted). Example 1: Consider (2s complement) Example 2: Consider (2s compl,) no carry Errors in numeric representations. When representing numeric data, the number of bits available for the representation is limited. Hence errors may occur. 1. PRECISION associated with the number of bits available to represent the fractional part of a given number. Cutajar&Cutajar

40 Consider: 1/2 1/4 1/8 1/16 1/32 1/64 1/128 1/ Using a 9-bit register: precision is 1/256 or 1/(2-8 ) Consider: 1/2 1/4 1/8 1/16 1/32 1/64 1/ Using an 8-bit register: precision is 1/128 or 1/(2-7 ) The more the number of bits for mantissa, the greater the precision. 2. ACCURACY is a measure of the closeness of an approximation to the true value. Consider the true (binary) number Using a 10-bit register: (error of ) (i) Using an 8-bit register: (error of ) (ii) Note that approximation (i) is more accurate than approximation (ii). Full accuracy for the true numbers requires 12 bits. 3. RANGE is the set of all numbers that can be represented by a particular system. Example 1: Assuming the following system; Fixed point representation in an 8-bit register using twos complement code to represent integer numbers: Range of this system is [-2 7, 2 7 1] = [-128, +127] Example 2: Assuming the following system: Floating-point representation using a 16-bit register with a 10-bit twos complement mantissa and a 6-bit twos complement exponent. For representing real numbers: Range of system is [-( * 10 9 ), +(2.1433* 10 9 )]. Cutajar&Cutajar

41 4. RESOLUTION - is the magnitude of the difference between the last two (least significant) adjacent digits or numbers. In the case of an 8-bit integer representation, the resolution is a constant 1 over the entire range (-128, +127). In the case of floating point representation, the resolution is not constant over the entire range and varies according to the value of the exponent being used. Example: Finding the resolution of a register which stores unsigned numbers in the format iiiiii.ff. Smallest number: = 0 Biggest number: = Thus the range is Although the range of the format is it does not mean that we can represent ANY number in this range. Since the register is 8-bits wide, there are still only 255 distinct values which can be represented. In this case the resolution is = In other words this format can represent numbers from IN STEPS of , 0.5, 0.75, 1.0, 1.25,, (256 numbers in all) Values in between these numbers cannot be represented accurately. The positioning of the point in fixed point representation is a compromise between RANGE and RESOLUTION. 5. TRUNCATION Consider to be represented in an 8-bit register truncated bits truncation error is : ( ) 6. ROUNDING Consider to be represented in an 8-bit register bits that cannot be represented Cutajar&Cutajar

42 When rounding a binary number, only the next consecutive digit in the binary bit sequence is considered. rounding error is : ( ) 7. OVERFLOW occurs when the upper bound of the range of the register in question is exceeded. UNDERFLOW is a term usually used in conjunction with floating point representations. When a value falls out of range in the unrepresented range: ] smallest magnitude negative number, smallest magnitude positive number[ an underflow is said to occur. Programs respond to underflow conditions in different ways. Some report an error while others approximate as best they can and continue processing (discussed above). Consider a 4-bit register: Range of 4-bit register is [-8, +7 ] Hence any number x, register x > 7 or x < -8, cannot be represented in this 4-bit Suppose adding (+5) and (+6) will result in overflow. 8. Errors introduced from decimal to binary conversions Decimal numbers are usually converted into binary and, for the majority of numbers an error (decrepency from true value) is already introduced at this stage before the numbers are used in calculations. Consider the following examples: Representing these numbers in a 4-bit register: = represented with no error but, = represented with error and furthermore, most numbers that are not multiples of binary fractions can never be represented exactly irrespective of the number of bits available = can never be represented exactly! Cutajar&Cutajar

43 Errors like these happen when most decimal fractions are input to a computer. However, it is usual to have a large number of binary digits, and this means that the decimal number is represented to a sensible number of places. Describing computational errors: (i) Actual error = exact value computed value where exact value is the value obtained in theory without any error computer value is the value obtained from the computer after it has been processed (ii) Relative error = actual error / exact value (iii) Absolute error = actual error (Magnitude of actual error) (iv) Absolute relative error = relative error (Magnitude of relative error) (v) Percentage error = relative error * 100 per cent Example: Consider 0.33 as an approximation of 1/3 Exact value = 1/3 Computed value = 0.33 Actual error = 1/3 33/100 = (100 99)/300 = 1/300 Relative error = (1/300) / (1/3) = 1/100 Percentage error = (1/100) * 100 = 1% Cutajar&Cutajar

44 Character Codes. As already stated, all data used by computers is in code form, namely binary code i.e. transfers computer stores manipulates data in code form. Data may be either numeric or character in type. We commonly refer to this data as alphanumeric data Numeric codes have already been discussed. We now discuss characters and how these are represented in digital format. Characters may be Printable characters - Letters A..Z, a..z - Digits Special characters ;,.? etc - Non printable characters Characters that cannot be displayed (printed) on screen or printed and are normally used for control purposes Examples: <delete>, <carriage return>, etc In order to code characters, a unique binary bit pattern is associated with each (symbol) character. All binary digits are stored in memory as positively and negatively charged magnetic spots. Because of the need to communicate information from one computer system to another, a unique set of codes for representing the different characters is required. Various standard coding systems have been developed (to answer needs and requirements of the time) to represent data in the computer and to conveniently transmit it between systems. Cutajar&Cutajar

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8 ECE Department Summer LECTURE #5: Number Systems EEL : Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz Decimal Number System: -Our standard number system is base, also

More information

Computer Science 281 Binary and Hexadecimal Review

Computer Science 281 Binary and Hexadecimal Review Computer Science 281 Binary and Hexadecimal Review 1 The Binary Number System Computers store everything, both instructions and data, by using many, many transistors, each of which can be in one of two

More information

Systems I: Computer Organization and Architecture

Systems I: Computer Organization and Architecture Systems I: Computer Organization and Architecture Lecture 2: Number Systems and Arithmetic Number Systems - Base The number system that we use is base : 734 = + 7 + 3 + 4 = x + 7x + 3x + 4x = x 3 + 7x

More information

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology LSN 2 Number Systems Department of Engineering Technology LSN 2 Decimal Number System Decimal number system has 10 digits (0-9) Base 10 weighting system... 10 5 10 4 10 3 10 2 10 1 10 0. 10-1 10-2 10-3

More information

The string of digits 101101 in the binary number system represents the quantity

The string of digits 101101 in the binary number system represents the quantity Data Representation Section 3.1 Data Types Registers contain either data or control information Control information is a bit or group of bits used to specify the sequence of command signals needed for

More information

Useful Number Systems

Useful Number Systems Useful Number Systems Decimal Base = 10 Digit Set = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Binary Base = 2 Digit Set = {0, 1} Octal Base = 8 = 2 3 Digit Set = {0, 1, 2, 3, 4, 5, 6, 7} Hexadecimal Base = 16 = 2

More information

Levent EREN levent.eren@ieu.edu.tr A-306 Office Phone:488-9882 INTRODUCTION TO DIGITAL LOGIC

Levent EREN levent.eren@ieu.edu.tr A-306 Office Phone:488-9882 INTRODUCTION TO DIGITAL LOGIC Levent EREN levent.eren@ieu.edu.tr A-306 Office Phone:488-9882 1 Number Systems Representation Positive radix, positional number systems A number with radix r is represented by a string of digits: A n

More information

CSI 333 Lecture 1 Number Systems

CSI 333 Lecture 1 Number Systems CSI 333 Lecture 1 Number Systems 1 1 / 23 Basics of Number Systems Ref: Appendix C of Deitel & Deitel. Weighted Positional Notation: 192 = 2 10 0 + 9 10 1 + 1 10 2 General: Digit sequence : d n 1 d n 2...

More information

Lecture 2. Binary and Hexadecimal Numbers

Lecture 2. Binary and Hexadecimal Numbers Lecture 2 Binary and Hexadecimal Numbers Purpose: Review binary and hexadecimal number representations Convert directly from one base to another base Review addition and subtraction in binary representations

More information

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic: Binary Numbers In computer science we deal almost exclusively with binary numbers. it will be very helpful to memorize some binary constants and their decimal and English equivalents. By English equivalents

More information

Numbering Systems. InThisAppendix...

Numbering Systems. InThisAppendix... G InThisAppendix... Introduction Binary Numbering System Hexadecimal Numbering System Octal Numbering System Binary Coded Decimal (BCD) Numbering System Real (Floating Point) Numbering System BCD/Binary/Decimal/Hex/Octal

More information

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1 Divide: Paper & Pencil Computer Architecture ALU Design : Division and Floating Point 1001 Quotient Divisor 1000 1001010 Dividend 1000 10 101 1010 1000 10 (or Modulo result) See how big a number can be

More information

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

EE 261 Introduction to Logic Circuits. Module #2 Number Systems EE 261 Introduction to Logic Circuits Module #2 Number Systems Topics A. Number System Formation B. Base Conversions C. Binary Arithmetic D. Signed Numbers E. Signed Arithmetic F. Binary Codes Textbook

More information

NUMBER SYSTEMS. William Stallings

NUMBER SYSTEMS. William Stallings NUMBER SYSTEMS William Stallings The Decimal System... The Binary System...3 Converting between Binary and Decimal...3 Integers...4 Fractions...5 Hexadecimal Notation...6 This document available at WilliamStallings.com/StudentSupport.html

More information

Number Representation

Number Representation Number Representation CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Topics to be Discussed How are numeric data

More information

Base Conversion written by Cathy Saxton

Base Conversion written by Cathy Saxton Base Conversion written by Cathy Saxton 1. Base 10 In base 10, the digits, from right to left, specify the 1 s, 10 s, 100 s, 1000 s, etc. These are powers of 10 (10 x ): 10 0 = 1, 10 1 = 10, 10 2 = 100,

More information

Binary, Hexadecimal, Octal, and BCD Numbers

Binary, Hexadecimal, Octal, and BCD Numbers 23CH_PHCalter_TMSETE_949118 23/2/2007 1:37 PM Page 1 Binary, Hexadecimal, Octal, and BCD Numbers OBJECTIVES When you have completed this chapter, you should be able to: Convert between binary and decimal

More information

NUMBER SYSTEMS. 1.1 Introduction

NUMBER SYSTEMS. 1.1 Introduction NUMBER SYSTEMS 1.1 Introduction There are several number systems which we normally use, such as decimal, binary, octal, hexadecimal, etc. Amongst them we are most familiar with the decimal number system.

More information

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal. Binary Representation The basis of all digital data is binary representation. Binary - means two 1, 0 True, False Hot, Cold On, Off We must be able to handle more than just values for real world problems

More information

2011, The McGraw-Hill Companies, Inc. Chapter 3

2011, The McGraw-Hill Companies, Inc. Chapter 3 Chapter 3 3.1 Decimal System The radix or base of a number system determines the total number of different symbols or digits used by that system. The decimal system has a base of 10 with the digits 0 through

More information

Lecture 11: Number Systems

Lecture 11: Number Systems Lecture 11: Number Systems Numeric Data Fixed point Integers (12, 345, 20567 etc) Real fractions (23.45, 23., 0.145 etc.) Floating point such as 23. 45 e 12 Basically an exponent representation Any number

More information

Chapter 1: Digital Systems and Binary Numbers

Chapter 1: Digital Systems and Binary Numbers Chapter 1: Digital Systems and Binary Numbers Digital age and information age Digital computers general purposes many scientific, industrial and commercial applications Digital systems telephone switching

More information

CPEN 214 - Digital Logic Design Binary Systems

CPEN 214 - Digital Logic Design Binary Systems CPEN 4 - Digital Logic Design Binary Systems C. Gerousis Digital Design 3 rd Ed., Mano Prentice Hall Digital vs. Analog An analog system has continuous range of values A mercury thermometer Vinyl records

More information

Binary Representation

Binary Representation Binary Representation The basis of all digital data is binary representation. Binary - means two 1, 0 True, False Hot, Cold On, Off We must tbe able to handle more than just values for real world problems

More information

plc numbers - 13.1 Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

plc numbers - 13.1 Encoded values; BCD and ASCII Error detection; parity, gray code and checksums plc numbers - 3. Topics: Number bases; binary, octal, decimal, hexadecimal Binary calculations; s compliments, addition, subtraction and Boolean operations Encoded values; BCD and ASCII Error detection;

More information

Goals. Unary Numbers. Decimal Numbers. 3,148 is. 1000 s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

Goals. Unary Numbers. Decimal Numbers. 3,148 is. 1000 s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1 Number Bases //9 Goals Numbers Understand binary and hexadecimal numbers Be able to convert between number bases Understand binary fractions COMP37 Introduction to Computer Architecture Unary Numbers Decimal

More information

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012 CDA 3200 Digital Systems Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012 Outline Data Representation Binary Codes Why 6-3-1-1 and Excess-3? Data Representation (1/2) Each numbering

More information

Solution for Homework 2

Solution for Homework 2 Solution for Homework 2 Problem 1 a. What is the minimum number of bits that are required to uniquely represent the characters of English alphabet? (Consider upper case characters alone) The number of

More information

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal: Exercises 1 - number representations Questions 1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal: (a) 3012 (b) - 435 2. For each of

More information

Section 1.4 Place Value Systems of Numeration in Other Bases

Section 1.4 Place Value Systems of Numeration in Other Bases Section.4 Place Value Systems of Numeration in Other Bases Other Bases The Hindu-Arabic system that is used in most of the world today is a positional value system with a base of ten. The simplest reason

More information

6 3 4 9 = 6 10 + 3 10 + 4 10 + 9 10

6 3 4 9 = 6 10 + 3 10 + 4 10 + 9 10 Lesson The Binary Number System. Why Binary? The number system that you are familiar with, that you use every day, is the decimal number system, also commonly referred to as the base- system. When you

More information

Binary Number System. 16. Binary Numbers. Base 10 digits: 0 1 2 3 4 5 6 7 8 9. Base 2 digits: 0 1

Binary Number System. 16. Binary Numbers. Base 10 digits: 0 1 2 3 4 5 6 7 8 9. Base 2 digits: 0 1 Binary Number System 1 Base 10 digits: 0 1 2 3 4 5 6 7 8 9 Base 2 digits: 0 1 Recall that in base 10, the digits of a number are just coefficients of powers of the base (10): 417 = 4 * 10 2 + 1 * 10 1

More information

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 04 Digital Logic II May, I before starting the today s lecture

More information

CS321. Introduction to Numerical Methods

CS321. Introduction to Numerical Methods CS3 Introduction to Numerical Methods Lecture Number Representations and Errors Professor Jun Zhang Department of Computer Science University of Kentucky Lexington, KY 40506-0633 August 7, 05 Number in

More information

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi) Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi) INTRODUCTION System- A number system defines a set of values to represent quantity. We talk about the number of people

More information

Binary Numbers. Binary Octal Hexadecimal

Binary Numbers. Binary Octal Hexadecimal Binary Numbers Binary Octal Hexadecimal Binary Numbers COUNTING SYSTEMS UNLIMITED... Since you have been using the 10 different digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 all your life, you may wonder how

More information

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal 2/9/9 Binary number system Computer (electronic) systems prefer binary numbers Binary number: represent a number in base-2 Binary numbers 2 3 + 7 + 5 Some terminology Bit: a binary digit ( or ) Hexadecimal

More information

Binary Numbering Systems

Binary Numbering Systems Binary Numbering Systems April 1997, ver. 1 Application Note 83 Introduction Binary numbering systems are used in virtually all digital systems, including digital signal processing (DSP), networking, and

More information

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit Decimal Division Remember 4th grade long division? 43 // quotient 12 521 // divisor dividend -480 41-36 5 // remainder Shift divisor left (multiply by 10) until MSB lines up with dividend s Repeat until

More information

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers This Unit: Floating Point Arithmetic CIS 371 Computer Organization and Design Unit 7: Floating Point App App App System software Mem CPU I/O Formats Precision and range IEEE 754 standard Operations Addition

More information

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30));

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30)); Introduction to Embedded Microcomputer Systems Lecture 5.1 2.9. Conversions ASCII to binary n = 100*(Data[0]-0x30) + 10*(Data[1]-0x30) + (Data[2]-0x30); This 3-digit ASCII string could also be calculated

More information

YOU MUST BE ABLE TO DO THE FOLLOWING PROBLEMS WITHOUT A CALCULATOR!

YOU MUST BE ABLE TO DO THE FOLLOWING PROBLEMS WITHOUT A CALCULATOR! DETAILED SOLUTIONS AND CONCEPTS - DECIMALS AND WHOLE NUMBERS Prepared by Ingrid Stewart, Ph.D., College of Southern Nevada Please Send Questions and Comments to ingrid.stewart@csn.edu. Thank you! YOU MUST

More information

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to: Chapter 3 Data Storage Objectives After studying this chapter, students should be able to: List five different data types used in a computer. Describe how integers are stored in a computer. Describe how

More information

2 Number Systems. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

2 Number Systems. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to: 2 Number Systems 2.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Understand the concept of number systems. Distinguish

More information

Unsigned Conversions from Decimal or to Decimal and other Number Systems

Unsigned Conversions from Decimal or to Decimal and other Number Systems Page 1 of 5 Unsigned Conversions from Decimal or to Decimal and other Number Systems In all digital design, analysis, troubleshooting, and repair you will be working with binary numbers (or base 2). It

More information

COMPSCI 210. Binary Fractions. Agenda & Reading

COMPSCI 210. Binary Fractions. Agenda & Reading COMPSCI 21 Binary Fractions Agenda & Reading Topics: Fractions Binary Octal Hexadecimal Binary -> Octal, Hex Octal -> Binary, Hex Decimal -> Octal, Hex Hex -> Binary, Octal Animation: BinFrac.htm Example

More information

3. Convert a number from one number system to another

3. Convert a number from one number system to another 3. Convert a number from one number system to another Conversion between number bases: Hexa (16) Decimal (10) Binary (2) Octal (8) More Interest Way we need conversion? We need decimal system for real

More information

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 TUTORIAL OUTCOME 2 Part 1

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 TUTORIAL OUTCOME 2 Part 1 UNIT 22: PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 TUTORIAL OUTCOME 2 Part 1 This work covers part of outcome 2 of the Edexcel standard module. The material is

More information

Recall the process used for adding decimal numbers. 1. Place the numbers to be added in vertical format, aligning the decimal points.

Recall the process used for adding decimal numbers. 1. Place the numbers to be added in vertical format, aligning the decimal points. 2 MODULE 4. DECIMALS 4a Decimal Arithmetic Adding Decimals Recall the process used for adding decimal numbers. Adding Decimals. To add decimal numbers, proceed as follows: 1. Place the numbers to be added

More information

A Step towards an Easy Interconversion of Various Number Systems

A Step towards an Easy Interconversion of Various Number Systems A towards an Easy Interconversion of Various Number Systems Shahid Latif, Rahat Ullah, Hamid Jan Department of Computer Science and Information Technology Sarhad University of Science and Information Technology

More information

Chapter 2. Binary Values and Number Systems

Chapter 2. Binary Values and Number Systems Chapter 2 Binary Values and Number Systems Numbers Natural numbers, a.k.a. positive integers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645, 32 Negative numbers A

More information

Positional Numbering System

Positional Numbering System APPENDIX B Positional Numbering System A positional numbering system uses a set of symbols. The value that each symbol represents, however, depends on its face value and its place value, the value associated

More information

Lecture 8: Binary Multiplication & Division

Lecture 8: Binary Multiplication & Division Lecture 8: Binary Multiplication & Division Today s topics: Addition/Subtraction Multiplication Division Reminder: get started early on assignment 3 1 2 s Complement Signed Numbers two = 0 ten 0001 two

More information

MATH-0910 Review Concepts (Haugen)

MATH-0910 Review Concepts (Haugen) Unit 1 Whole Numbers and Fractions MATH-0910 Review Concepts (Haugen) Exam 1 Sections 1.5, 1.6, 1.7, 1.8, 2.1, 2.2, 2.3, 2.4, and 2.5 Dividing Whole Numbers Equivalent ways of expressing division: a b,

More information

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations ECE 0142 Computer Organization Lecture 3 Floating Point Representations 1 Floating-point arithmetic We often incur floating-point programming. Floating point greatly simplifies working with large (e.g.,

More information

CHAPTER 5 Round-off errors

CHAPTER 5 Round-off errors CHAPTER 5 Round-off errors In the two previous chapters we have seen how numbers can be represented in the binary numeral system and how this is the basis for representing numbers in computers. Since any

More information

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T) Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating

More information

Numerical Matrix Analysis

Numerical Matrix Analysis Numerical Matrix Analysis Lecture Notes #10 Conditioning and / Peter Blomgren, blomgren.peter@gmail.com Department of Mathematics and Statistics Dynamical Systems Group Computational Sciences Research

More information

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Data Storage 3.1. Foundations of Computer Science Cengage Learning 3 Data Storage 3.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List five different data types used in a computer. Describe how

More information

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012 Binary numbers The reason humans represent numbers using decimal (the ten digits from 0,1,... 9) is that we have ten fingers. There is no other reason than that. There is nothing special otherwise about

More information

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals: Numeral Systems Which number is larger? 25 8 We need to distinguish between numbers and the symbols that represent them, called numerals. The number 25 is larger than 8, but the numeral 8 above is larger

More information

Chapter 4: Computer Codes

Chapter 4: Computer Codes Slide 1/30 Learning Objectives In this chapter you will learn about: Computer data Computer codes: representation of data in binary Most commonly used computer codes Collating sequence 36 Slide 2/30 Data

More information

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer Computers CMPT 125: Lecture 1: Understanding the Computer Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 A computer performs 2 basic functions: 1.

More information

The Hexadecimal Number System and Memory Addressing

The Hexadecimal Number System and Memory Addressing APPENDIX C The Hexadecimal Number System and Memory Addressing U nderstanding the number system and the coding system that computers use to store data and communicate with each other is fundamental to

More information

Numeration systems. Resources and methods for learning about these subjects (list a few here, in preparation for your research):

Numeration systems. Resources and methods for learning about these subjects (list a few here, in preparation for your research): Numeration systems This worksheet and all related files are licensed under the Creative Commons Attribution License, version 1.0. To view a copy of this license, visit http://creativecommons.org/licenses/by/1.0/,

More information

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011 CS101 Lecture 11: Number Systems and Binary Numbers Aaron Stevens 14 February 2011 1 2 1 3!!! MATH WARNING!!! TODAY S LECTURE CONTAINS TRACE AMOUNTS OF ARITHMETIC AND ALGEBRA PLEASE BE ADVISED THAT CALCULTORS

More information

Lies My Calculator and Computer Told Me

Lies My Calculator and Computer Told Me Lies My Calculator and Computer Told Me 2 LIES MY CALCULATOR AND COMPUTER TOLD ME Lies My Calculator and Computer Told Me See Section.4 for a discussion of graphing calculators and computers with graphing

More information

Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6

Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6 Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6 Number Systems No course on programming would be complete without a discussion of the Hexadecimal (Hex) number

More information

MACHINE INSTRUCTIONS AND PROGRAMS

MACHINE INSTRUCTIONS AND PROGRAMS CHAPTER 2 MACHINE INSTRUCTIONS AND PROGRAMS CHAPTER OBJECTIVES In this chapter you will learn about: Machine instructions and program execution, including branching and subroutine call and return operations

More information

Correctly Rounded Floating-point Binary-to-Decimal and Decimal-to-Binary Conversion Routines in Standard ML. By Prashanth Tilleti

Correctly Rounded Floating-point Binary-to-Decimal and Decimal-to-Binary Conversion Routines in Standard ML. By Prashanth Tilleti Correctly Rounded Floating-point Binary-to-Decimal and Decimal-to-Binary Conversion Routines in Standard ML By Prashanth Tilleti Advisor Dr. Matthew Fluet Department of Computer Science B. Thomas Golisano

More information

Binary Adders: Half Adders and Full Adders

Binary Adders: Half Adders and Full Adders Binary Adders: Half Adders and Full Adders In this set of slides, we present the two basic types of adders: 1. Half adders, and 2. Full adders. Each type of adder functions to add two binary bits. In order

More information

CS201: Architecture and Assembly Language

CS201: Architecture and Assembly Language CS201: Architecture and Assembly Language Lecture Three Brendan Burns CS201: Lecture Three p.1/27 Arithmetic for computers Previously we saw how we could represent unsigned numbers in binary and how binary

More information

Decimal to Binary Conversion

Decimal to Binary Conversion Decimal to Binary Conversion A tool that makes the conversion of decimal values to binary values simple is the following table. The first row is created by counting right to left from one to eight, for

More information

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın Digital Design Assoc. Prof. Dr. Berna Örs Yalçın Istanbul Technical University Faculty of Electrical and Electronics Engineering Office Number: 2318 E-mail: siddika.ors@itu.edu.tr Grading 1st Midterm -

More information

Section 4.1 Rules of Exponents

Section 4.1 Rules of Exponents Section 4.1 Rules of Exponents THE MEANING OF THE EXPONENT The exponent is an abbreviation for repeated multiplication. The repeated number is called a factor. x n means n factors of x. The exponent tells

More information

Number and codes in digital systems

Number and codes in digital systems Number and codes in digital systems Decimal Numbers You are familiar with the decimal number system because you use them everyday. But their weighted structure is not understood. In the decimal number

More information

Number Systems and Radix Conversion

Number Systems and Radix Conversion Number Systems and Radix Conversion Sanjay Rajopadhye, Colorado State University 1 Introduction These notes for CS 270 describe polynomial number systems. The material is not in the textbook, but will

More information

26 Integers: Multiplication, Division, and Order

26 Integers: Multiplication, Division, and Order 26 Integers: Multiplication, Division, and Order Integer multiplication and division are extensions of whole number multiplication and division. In multiplying and dividing integers, the one new issue

More information

Session 29 Scientific Notation and Laws of Exponents. If you have ever taken a Chemistry class, you may have encountered the following numbers:

Session 29 Scientific Notation and Laws of Exponents. If you have ever taken a Chemistry class, you may have encountered the following numbers: Session 9 Scientific Notation and Laws of Exponents If you have ever taken a Chemistry class, you may have encountered the following numbers: There are approximately 60,4,79,00,000,000,000,000 molecules

More information

Click on the links below to jump directly to the relevant section

Click on the links below to jump directly to the relevant section Click on the links below to jump directly to the relevant section What is algebra? Operations with algebraic terms Mathematical properties of real numbers Order of operations What is Algebra? Algebra is

More information

The BBP Algorithm for Pi

The BBP Algorithm for Pi The BBP Algorithm for Pi David H. Bailey September 17, 2006 1. Introduction The Bailey-Borwein-Plouffe (BBP) algorithm for π is based on the BBP formula for π, which was discovered in 1995 and published

More information

Working with whole numbers

Working with whole numbers 1 CHAPTER 1 Working with whole numbers In this chapter you will revise earlier work on: addition and subtraction without a calculator multiplication and division without a calculator using positive and

More information

8 Divisibility and prime numbers

8 Divisibility and prime numbers 8 Divisibility and prime numbers 8.1 Divisibility In this short section we extend the concept of a multiple from the natural numbers to the integers. We also summarize several other terms that express

More information

Number Systems. Introduction / Number Systems

Number Systems. Introduction / Number Systems Number Systems Introduction / Number Systems Data Representation Data representation can be Digital or Analog In Analog representation values are represented over a continuous range In Digital representation

More information

The finite field with 2 elements The simplest finite field is

The finite field with 2 elements The simplest finite field is The finite field with 2 elements The simplest finite field is GF (2) = F 2 = {0, 1} = Z/2 It has addition and multiplication + and defined to be 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0 0 0 = 0 0 1 = 0

More information

Basic Use of the TI-84 Plus

Basic Use of the TI-84 Plus Basic Use of the TI-84 Plus Topics: Key Board Sections Key Functions Screen Contrast Numerical Calculations Order of Operations Built-In Templates MATH menu Scientific Notation The key VS the (-) Key Navigation

More information

HOMEWORK # 2 SOLUTIO

HOMEWORK # 2 SOLUTIO HOMEWORK # 2 SOLUTIO Problem 1 (2 points) a. There are 313 characters in the Tamil language. If every character is to be encoded into a unique bit pattern, what is the minimum number of bits required to

More information

Pre-Algebra Lecture 6

Pre-Algebra Lecture 6 Pre-Algebra Lecture 6 Today we will discuss Decimals and Percentages. Outline: 1. Decimals 2. Ordering Decimals 3. Rounding Decimals 4. Adding and subtracting Decimals 5. Multiplying and Dividing Decimals

More information

Measures of Error: for exact x and approximation x Absolute error e = x x. Relative error r = (x x )/x.

Measures of Error: for exact x and approximation x Absolute error e = x x. Relative error r = (x x )/x. ERRORS and COMPUTER ARITHMETIC Types of Error in Numerical Calculations Initial Data Errors: from experiment, modeling, computer representation; problem dependent but need to know at beginning of calculation.

More information

PAYCHEX, INC. BASIC BUSINESS MATH TRAINING MODULE

PAYCHEX, INC. BASIC BUSINESS MATH TRAINING MODULE PAYCHEX, INC. BASIC BUSINESS MATH TRAINING MODULE 1 Property of Paychex, Inc. Basic Business Math Table of Contents Overview...3 Objectives...3 Calculator...4 Basic Calculations...6 Order of Operation...9

More information

Paramedic Program Pre-Admission Mathematics Test Study Guide

Paramedic Program Pre-Admission Mathematics Test Study Guide Paramedic Program Pre-Admission Mathematics Test Study Guide 05/13 1 Table of Contents Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Page 9 Page 10 Page 11 Page 12 Page 13 Page 14 Page 15 Page

More information

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions. Unit 1 Number Sense In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions. BLM Three Types of Percent Problems (p L-34) is a summary BLM for the material

More information

NUMBER SYSTEMS APPENDIX D. You will learn about the following in this appendix:

NUMBER SYSTEMS APPENDIX D. You will learn about the following in this appendix: APPENDIX D NUMBER SYSTEMS You will learn about the following in this appendix: The four important number systems in computing binary, octal, decimal, and hexadecimal. A number system converter program

More information

BINARY CODED DECIMAL: B.C.D.

BINARY CODED DECIMAL: B.C.D. BINARY CODED DECIMAL: B.C.D. ANOTHER METHOD TO REPRESENT DECIMAL NUMBERS USEFUL BECAUSE MANY DIGITAL DEVICES PROCESS + DISPLAY NUMBERS IN TENS IN BCD EACH NUMBER IS DEFINED BY A BINARY CODE OF 4 BITS.

More information

Math Review. Numbers. Place Value. Rounding Whole Numbers. Place value thousands hundreds tens ones

Math Review. Numbers. Place Value. Rounding Whole Numbers. Place value thousands hundreds tens ones Math Review Knowing basic math concepts and knowing when to apply them are essential skills. You should know how to add, subtract, multiply, divide, calculate percentages, and manipulate fractions. This

More information

THE BINARY NUMBER SYSTEM

THE BINARY NUMBER SYSTEM THE BINARY NUMBER SYSTEM Dr. Robert P. Webber, Longwood University Our civilization uses the base 10 or decimal place value system. Each digit in a number represents a power of 10. For example, 365.42

More information

AN617. Fixed Point Routines FIXED POINT ARITHMETIC INTRODUCTION. Thi d t t d ith F M k 4 0 4. Design Consultant

AN617. Fixed Point Routines FIXED POINT ARITHMETIC INTRODUCTION. Thi d t t d ith F M k 4 0 4. Design Consultant Thi d t t d ith F M k 4 0 4 Fixed Point Routines AN617 Author: INTRODUCTION Frank J. Testa Design Consultant This application note presents an implementation of the following fixed point math routines

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Vector and Matrix Norms

Vector and Matrix Norms Chapter 1 Vector and Matrix Norms 11 Vector Spaces Let F be a field (such as the real numbers, R, or complex numbers, C) with elements called scalars A Vector Space, V, over the field F is a non-empty

More information