Download presentation
Presentation is loading. Please wait.
Published bySheila Gaines Modified over 8 years ago
1
Number Representation 1 Lecture 2
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.
3
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
4
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).
5
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.
6
Decimalmsb Lsb 1286432168421 25511111111 800001000 3300100001 9901100011 4600101110
7
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.
8
HexadecimalBinaryDecimal 000000 100011 200102 300113 401004 501015 601106 701117 810008 910019 A101010 B101111 C110012 D110113 E111014 F111115
9
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.
10
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.
11
2’s complement If 10000001 was stored the msb =-128 and the rest equals 1 so the number is –128+1=-127. If 00000001 was stored the msb =0 and the rest equals 1 so the number this time is 0+1=1
12
-12810000000 -12710000001 -12610000010 ::::::::: -311111101 -211111110 11111111 000000000 +100000001 +200000010 +300000011 :::::::: +12401111100 +12501111101 +12601111110 +12701111111
13
So with 8-bit 2’s complement we can represent numbers between –128 and +127. -126 =10000010 +126 = 01111110 If we reverse all the bits in –126 we get 01111101 if we add 1 to this we get 01111110
14
Starting Number = -12610000010 Reverse bits01111101 Add 101111110 +12601111110 Positive to negative and back
15
Summary Introduced – Binary – Hexadecimal Storing negative and positive numbers – Sign and magnitude – 2’s complement.
16
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 12.56 in a computer?
17
Further reading Chalk et al (2004) pg 10-19 Tannebaum (2005) Pages 69-70, 679-690
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.