1 / 25

COMP201 Computer Systems Number Representation

COMP201 Computer Systems Number Representation. Number Representation. Introduction Number Systems Integer Representations Examples Englander Chapter 2 and Chapter 4. Introduction. Data must be converted to Binary before it can be stored in Computer. Introduction.

Télécharger la présentation

COMP201 Computer Systems Number Representation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMP201 Computer SystemsNumber 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. Computers store and Manipulate numbers using the binary (base 2) number system Base 10 = 510 Roman = V Binary = 1012 Base3 = 123 Number Representation

  7. Binary Representation • Each bit represents a value two times the value of the bit to it’s right. Dec Bin 0 000 = 0x22 + 0x21 + 0x20 1 001 = 0x22 + 0x21 + 1x20 2 010 = 0x22 + 1x21 + 0x20 3 011 = 0x22 + 1x21 + 1x20 4 100 = 1x22 + 0x21 + 0x20

  8. Octal Representation • Each octal number can be perfectly represented by 3 binary digits • 0 000 • 001 • 010 • 011 • 100 • 101 • 110 • 111 010 110 101 001 = 26518 =??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. • 0 0000 • 0001 • 0010 • 0011 • 0100 • 0101 • 0110 • 0111 • 1000 • 1001 • A 1010 • B 1011 • C 1100 • D 1101 • E 1110 • F 1111 0010 1110 1010 0001 = 2EA116

  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 Decimal Octal Hexadecimal Binary 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, 2610 = 20 + 6 = 2 x 101 + 6 x 100 • This leads to methods for converting between bases. 26518= 2 x 83 + 6 x 82 + 5 x 81+ 1 x 80 • Substitute decimal values for powers of 8 to convert 26518 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. 35910 = 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 410= 00000100 • And two digits, 4510, 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. • 4510= 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 -2n-1 to (2n-1-1) • Only one representation of zero Binary Negative Compliment 0 1 1 0 Positive +1 Result

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

  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

More Related