Number Representation 1 Lecture 2
Outcomes By the end of the session you should: – Understand what bits/bytes/words are. – Understanding conversion between binary, decimal and hexadecimal. – Understand how negative numbers can be stored.
Numbering Systems (Decimal) The counting system most commonly used by humans in the west, often believed to be based on the number of fingers on two hands. There are ten digits in this counting system
Numbering Systems (Binary) The two-state nature of logic gates means the use of 0 or 1, as the basic unit of the count is natural. Data is represented by binary digits (bits), words are groups of bits, but by convention the size of words are multiples of 8 bits (or a byte). bit furthest right as the least significant bit (lsb) and bit furthest left as the most significant bit as the most significant bit (msb).
Where we are only dealing with the positive integers the msb is the representation of largest power of 2, this as we will see later is not always true. In an n-bit word there are 2 n different combinations of bit, – so for 2 bits(n=2) there are 4 combinations, – for n=5 32 combinations.
Decimalmsb Lsb
Numbering system (Hexadecimal) A base-16 system with 16 possible digits {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}. Each hexadecimal number can be represented by 4 bits.
HexadecimalBinaryDecimal A B C D E F111115
Negative and Positive Numbers So far is the discussion no mention has been made about the being able to represent negative numbers, how can both negative and positive number be stored. Two methods – Sign and Magnitude – 2’s complement.
2’s complement There is an alternative, which allows addition and subtraction to be treated in the same way. 2’s complement has the ‘sign’ of the number built in. This achieved by the most significant bit the value –2 n-1 having a negative value so if n=8 this is –128 and the rest of the bits are unsigned bits.
2’s complement If was stored the msb =-128 and the rest equals 1 so the number is –128+1=-127. If was stored the msb =0 and the rest equals 1 so the number this time is 0+1=1
::::::::: ::::::::
So with 8-bit 2’s complement we can represent numbers between –128 and = = If we reverse all the bits in –126 we get if we add 1 to this we get
Starting Number = Reverse bits Add Positive to negative and back
Summary Introduced – Binary – Hexadecimal Storing negative and positive numbers – Sign and magnitude – 2’s complement.
Practical this week and Next Weeks sessions This weeks practical – Number representation – Adding binary numbers Next Week – Subtracting in binary – How do we represent number such as in a computer?
Further reading Chalk et al (2004) pg Tannebaum (2005) Pages 69-70,