Notes
Outline
COM1100
Fundamentals of Computer Science –Winter 2000
Lecture 22
03/06/00
Lecture today
Number system
Decimal number system
Binary number system
Hexadecimal number system
Octal number system (not required for this course)
How to convert from one number system to another?
Convert decimal number to binary number
Convert binary number to decimal number
Convert hexadecimal number to binary number
Convert binary number to hexadecimal number
Decimal number system
The decimal number system is the most popular number system and it is the one people are most familiar with.
Its origin is probably related to the fact that human beings have 10 fingers.
It uses the 10 symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and the base is 10.
The lowest digit is 0 and the highest digit is 9 – one less than the base of 10.
Decimal number expression
A decimal number can thus be expressed as:
dn * 10 n + dn-1 * 10 n-1 + …+ d1 * 101 + d0 * 10 0
where, dj  is one of the ten decimal digits  0 ~ 9
             10i  is the power of 10 of each digit dj that defines its positional significance, or simply the power of that digit.
For example,
( 845 )10   = 8 * 102 + 4 * 101 + 5 * 100
   = 8 * 100 + 4 * 10 + 5 * 1
We will use ( 845 )10 to represent a decimal number.
Binary number system
In the binary number system the base is 2.
There are only two symbols, 0 and 1, called binary digits or bits in short.
Its lowest digit is 0 and its highest digit is 1 which is one less than the base of 2.
Binary number expression
A binary number can thus be expressed as:
dn * 2 n + dn-1 * 2 n-1 + …+ d1 * 21 + d0 * 2 0
where, dj  is one of the two binary digits  0 ~ 1
         2i is the power of 2 of each digit dj that defines its positional significance, or simply the power of that digit.
We will use (110011)2 to represent a binary number.
Least significant bit (LSB, the right-most bit)
Most significant bit (MSB, the left-most bit)
Hexadecimal number system
The hexadecimal number system has base 16 and therefore it requires 16 symbols – a lowest digit of 0 and a highest digit with a value equivalent to decimal 15 (one less than the base of 16).
By convention, we use letter A through F to represent the hexadecimal digits corresponding to decimal values 10 through 15.
In other words, hexadecimal number system uses the 16 symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
Hexadecimal number system
In hexadecimal number system, we can have :
numbers like 876 consisting solely of decimal-like digits,
numbers like 8A55F consisting of digits and letters,
and numbers like FFE consisting solely of letters.
Occasionally, a hexadecimal number spells a common word such as FACE or FEED which can appear strange to programmers.
Hexadecimal number expression
A hexadecimal number can thus be expressed as:
dn * 16 n + dn-1 * 16 n-1 + …+ d1 * 161 + d0 * 16 0
where, dj is one of the 16 hexadecimal digits  0 ~ 9 and A ~ F
16i is the power of 16 of each digit dj that defines its positional significance, or simply the power of that digit.
For example,
( 3DA )16   = 3 * 162 + 13 * 161 + 10 * 160
                =  3 * 256 + 208 + 10
          =  768 + 208 +10
                =  986
We will use ( 3DA )16 to represent a hexadecimal number.
Binary number to decimal number
Decimal number to binary number
Divide the decimal number by 2.
The remainder is the binary bit, beginning with the least significant bit(LSB).
Continue dividing by 2 until you are left with 0, and a remainder of either 1 or 0.
The Last remainder is the most significant bit(MSB) of the binary number.
Decimal number to binary number
(123)10 = ( ? )2
Show ˝ Show the remainder
123 1 (LSB)
  61 1
  30 0
  15 1
   7 1
       3 1
   1 1
   0 0 (MSB)
So, (123)10 = ( 0111 1011 )2
Binary number to Hexadecimal number
    Binary number Hexadecimal number
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F
Binary number to Hexadecimal number
Group bits into sets of 4
Add leading 0 if needed
Check the table in slide no.13
For example,
( 111 1011 )2 = ( 0111  1011 )2
                          = (   7       B     )16
Hexadecimal number to Binary number
Check the table in slide no.13
May remove leading 0
For example,
(   7       B     )16  = ( 0111  1011 )2
= ( 111  1011 )2