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 Format used will depend on data: e.g. consider the number 9 9 may be represented as may be represented as may be represented as the character 9 may be represented as And the intended purpose of the number within the computer
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
Number Representation Computers store and Manipulate numbers using the binary (base 2) number system Base 10 = 5 10 Roman = V Binary = Base3 = 12 3
Binary Representation Each bit represents a value two times the value of the bit to it’s right. Dec Bin 0000 = 0x x x = 0x x x = 0x x x = 0x x x = 1x x x2 0
Octal Representation Each octal number can be perfectly represented by 3 binary digits = =?? 10
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 A1010 B1011 C1100 D1101 E1110 F = 2EA1 16
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
Number Conversion methods Place value: the value of a digit depends upon its placement relative to a reference, say a decimal point. For instance, = = 2 x x 10 0 This leads to methods for converting between bases = 2 x x x x 8 0 Substitute decimal values for powers of 8 to convert into decimal equivalent (1456)
Integer Representations BCD (binary coded decimal) Sign and Magnitude Excess Notation Two’s complement
BCD (Binary Coded Decimal) Each Decimal digit is coded as a 4 bit binary code Developed for early calculators e.g = bcd 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
BCD Example Each Decimal digit is coded as a 4 bit binary code 4 10 = And two digits, 45 10, would be stored in two different memory locations!
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. = in packed BCD BCD used in some old financial software and calculators, but now very rare.
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
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 = = Simple to find the sign Two values for zero Must process sign separately
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
Ones Complement Negative numbers formed by inverting the positive representation (logical NOT) E.g. +24 = = Two values for zero Addition requires carry bit to be wrapped around
Two’s Complement To negate a number invert the bits (logical NOT) then add one. E.g. +24 = invert Add one -24 = = Works for converting negative to positive as well
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
Two’s Complement– another viewpoint: The number wheel (For 4 bits)Reference: Katz: Contemporary Logic Design, p243
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 = = = =
Two’s Complement Examples Express the following in 2’s complement notation (use 16 bit form): Add the following 2’s complement numbers (they are 12 bits):
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