Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.

Similar presentations


Presentation on theme: "COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter."— Presentation transcript:

1 COMP201 Computer Systems Number Representation

2 Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter 2 and Chapter 4.

3 Introduction Data must be converted to Binary before it can be stored in Computer

4 Introduction Format used will depend on data:  e.g. consider the number 9 9 may be represented as 1001 -9 may be represented as 10111 9.0 may be represented as 0000010010000001 the character 9 may be represented as 0111001 And the intended purpose of the number within the computer

5 Considerations  When a coding format is being devised a number of considerations need to be made: Ease of manipulation Conciseness and machine efficiency Accuracy sufficient for problem Standardised data communication

6 Number Representation Computers store and Manipulate numbers using the binary (base 2) number system Base 10 = 5 10 Roman = V Binary = 101 2 Base3 = 12 3

7 Binary Representation Each bit represents a value two times the value of the bit to it’s right. Dec Bin 0000 = 0x2 2 + 0x2 1 + 0x2 0 1001 = 0x2 2 + 0x2 1 + 1x2 0 2010 = 0x2 2 + 1x2 1 + 0x2 0 3011 = 0x2 2 + 1x2 1 + 1x2 0 4100 = 1x2 2 + 0x2 1 + 0x2 0

8 Octal Representation Each octal number can be perfectly represented by 3 binary digits 0000 1001 2010 3011 4100 5101 6110 7111 010 110 101 001 = 2651 8 =?? 10

9 Hexadecimal Representation Each Hex number can be perfectly represented by 4 binary digits Two Hex digits can be used to represent a byte; four for a word. 00000 10001 20010 30011 40100 50101 60110 70111 81000 91001 A1010 B1011 C1100 D1101 E1110 F1111 0010 1110 1010 0001 = 2EA1 16

10 Number Conversion methods (You should have already studied this in a previous class. If you did not, or don’t remember, study Chapter 2 in detail.) Base= number of characters in system DecimalOctalHexadecimalBinary 10 8 16 2

11 Number Conversion methods Place value: the value of a digit depends upon its placement relative to a reference, say a decimal point. For instance, 26 10 = 20 + 6 = 2 x 10 1 + 6 x 10 0 This leads to methods for converting between bases. 2651 8 = 2 x 8 3 + 6 x 8 2 + 5 x 8 1 + 1 x 8 0 Substitute decimal values for powers of 8 to convert 2651 8 into decimal equivalent (1456)

12 Integer Representations BCD (binary coded decimal) Sign and Magnitude Excess Notation Two’s complement

13 BCD (Binary Coded Decimal) Each Decimal digit is coded as a 4 bit binary code Developed for early calculators  e.g. 359 10 = 0011 0101 1001bcd Easy for people to understand, Hard for computers to work with Signed Magnitude  Extra bit added to the code to represent the sign  In most cases a 0 represents a +ve a 1 represents a –ve

14 BCD Example Each Decimal digit is coded as a 4 bit binary code 4 10 = 00000100 And two digits, 45 10, would be stored in two different memory locations! 00000100 00000101

15 Packed BCD Packed BCD simply makes use of the storage space normally wasted in storage of BCD, by using the leftmost 4-bits (nibble) for one digit, and the rightmost nibble for another.  45 10 = 01000101 in packed BCD BCD used in some old financial software and calculators, but now very rare.

16 Sign Negative integers are often required Computers do not have internal minus signs There are several ways to represent negative and positive integers Choice is often based on the ease of manipulation for the intended purpose

17 Sign and Magnitude One of the simplest systems is to allocate one bit as the “sign” bit. The other bits are the “magnitude”.  E.g. +24 = 00011000 -24 = 10011000 Simple to find the sign Two values for zero Must process sign separately

18 Excess Notation  fix number of bit positions used  smallest number with 1 in the MSB represents zero (e.g. 1000)  All bit strings greater than this represent +ve numbers  All bit strings less than this represent -ve numbers  Example is known as excess eight notation because 8 (1000) represents zero

19 Ones Complement Negative numbers formed by inverting the positive representation (logical NOT)  E.g. +24 = 00011000 -24 = 11100111 Two values for zero Addition requires carry bit to be wrapped around

20 Two’s Complement To negate a number invert the bits (logical NOT) then add one.  E.g. +24 = 00011000 invert 11100111 Add one -24 = 11100111 + 1 -24 = 11101000 Works for converting negative to positive as well

21 Two’s Complement  Can represent numbers in the range -2 n-1 to (2 n-1 -1)  Only one representation of zero Binary Result Positive Negative Compliment 0 1 1 0 +1

22 Two’s Complement– another viewpoint: The number wheel 0000 0111 0011 1011 1111 1110 1101 1100 1010 1001 1000 0110 0101 0100 0010 0001 +0 +1 +2 +3 +4 +5 +6 +7 -8 -7 -6 -5 -4 -3 -2 (For 4 bits)Reference: Katz: Contemporary Logic Design, p243

23 Two’s Complement Leftmost bit is always the sign bit All zeroes is the only representation of zero Simple to implement negation, addition and subtraction in hardware. Can be sign extended +510 = 00000101 = 0000000000000101 -510 = 11111011 = 1111111111111011

24 Two’s Complement Examples Express the following in 2’s complement notation (use 16 bit form):  10000  100111100001001  0100111000100100 Add the following 2’s complement numbers (they are 12 bits): 011001101101 111010111011

25 Format Use Ones complement common in older computer hardware Two’s complement most common signed integer representation today. Sign and magnitude used in some very early computers Sign and magnitude and Excess notation both used in common floating point formats


Download ppt "COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter."

Similar presentations


Ads by Google