Review of Number System
Review of Number System
Hexadecimal number
Better representation of binary number is in form of hexadecimal. Imagine you have 1010100100100010111010112 . Can you remember all it? That number is common in computer language. For easier representation, we use hexadecimal number. Or in short, hex number. 1010100100100010111010112 can be represented by hex number A922EB which is easier to remember. How to change from long binary number to short hex number? First seperate binary number into groups of four. 1010 1001 0010 0010 1110 1011
Change each group to equivalent decimal 1010 10 1001 9 0010 2 0010 2 1110 14 1011 11
Replace value of 10 to 15 to equaivalent A to F 1010 10 A It is that simple. 1001 9 9 0010 2 2 0010 2 2 1110 14 E 1011 11 B
Binary addition
Two arithmetic operation done a lot in a computer is addition and subtraction. They do it in binary. In binary there are only two digits. So the addition works just like decimal addition. For example, you add 9 and 1 you will get 10. Why? because in decimal, 9 is the largest digit and after it there is no other digit.
2 Therefore when it is added with 1, it will return to 0 and there will be 1 carry forward making the answer 10. So does the binary. If you add 1 and 1 you will get 10 since 1 is the largest number. The reasoning is the same. Example 11111 10010110 +00111011 11010001 carry bits rst number = 150 (or 96H ) second number = 59 (or 3BH ) result = 209 (or D1H )
Binary subtraction
We use addition to do subtraction in microprocessor. For example, subtracting 50 from 18 is actually adding 50 with 18. To convert 18 to 18 we use technique called 2 s complement. We do the following to nd 2s complement. 00010010 11101101 + 1 11101110 positive 18 in 8-bit binary complement each bit add 1 the 2s complement of 18
2s complement is the way we interpret a binary number. The 18 representation of 11101110 must be interpret as a signed number. A signed number uses the MSB as the sign. 0 means positive and 1 means negative. So we have 00010010 11101110 +18, sign bit is 0 18, sign bit is 1
So now if we add 50 and 18 using binary, we have 111111 00110010 +11101110 00100000 carry bits 50 18 32