Internetworking Basics

  •  

     Chapter 1: Introduction to Networking


    The Hexadecimal Number System

    These notes guide you through understanding the hexadecimal number system.

    Introduction
    Overview of Hexadecimal
    Hexadecimal Number System

    ~~Hex and Decimal~~
              Hex to Decimal Conversions
              Decimal To Hex Conversions

    ~~Hex and Binary~~
              Hex to Binary Conversions
              Binary To Hex Conversions

    Summary

     
     

    Introduction

    On completion of these notes you should be

    • Understand the hexadecimal number system
    • Be able to convert from hex to decimal and vice versa
    • Be able to convert from hex to binary and vice versa
     

    Overview

    Quite often it is convenient for programmers to write a computer's binary code in octal or hexadecimal.  Converting octal or hexadecimal numbers to binary is easier than converting decimal to binary.  Hexadecimal is used in preference to octal because computers organize memory in groups of 8 bits (bytes) and these can be conveniently divided into groups of four bits (nibbles).  

    Four bits is easily coded in hexadecimal form.

     

    Hexadecimal Number System

    The hexadecimal number system has sixteen symbols...

    0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

    This means the base of the hexadecimal system must be 16.  So, each place value is weighted by a power of sixteen.  A place value table for the hexadecimal system would look like...
       

    163 162 161 160 . 16-1 16-2 16-3
    4096  256  16   1   decimal point sixteenth 1/256 1/4096 

    1  

    0  

    So, the hexadecimal number 1016 means 1 sixteen +  0 units.  

    Again, this number 1016 is not the same as the number 1010 in the denary system.  We will see how to convert the number to decimal later on.

     

    Hex to Decimal Conversions

    Suppose we have the hexadecimal number 3A16.

    161

    16
    16 1

    3

    A

    Well 3A16 is equivalent to 3×16 + A×1.  Which is 48 + (10×1) = 5810.  

    So to convert a hexadecimal number to denary, all we do is multiply each hexadecimal digit by it's place value and add them all together.

    Here are a few more examples.

    B316 = B×16 + 3×1 = (11×16) + 3 = 17910

    5F16 = 5×16 + F×1 = 80 + 15 = 9510

    CD16 = C×16 + D×1 = 12×16 + 13×1 = 8510

    ~Now try the activity~

     Activity A
    1. Convert the following hexadecimal numbers to denary
    1. AB16
    2. 5E16
    3. C016
    4. FF16
     

    Decimal to Hex Conversions

    How do we convert a denary number to hexadecimal?  Using a place value table, this is similar to converting a denary number to binary.  

    As an example, suppose we want to convert 3510 to hexadecimal?  Lets look at a place value table..

    161

    160 
    16   1  

        

    Looking at the place value table, the nearest place value less than or equal to 35 is 1635 divided by 16 is 2 leaving a remainder of 3.  So we can write a 2 below the place value of 16.  

    Now, considering the remainder of 3.  The nearest place value less than or equal to 3 is 1.  Since we need 3 amounts of 1 we can write a 3 below the place value of 1.   There is no remainder.  

    So, 3510 is equivalent to 2316 

    161

    160 
    16  

    2  

    3  

    = 3510

    ~Now try the activity~

     Activity B
    1. Convert the following denary numbers to hexadecimal
    1. 12910
    2. 4010
    3. 10110
    4. 25310
    1. Extend the following table to include the hexadecimal numbers 2 to F and their binary equivalents.
    Base16 Base2
    0 0000
    1 0001
     

    Binary to Hex Conversions

    How do we convert a binary number to hexadecimal?  

    If a binary number is a byte long (8 bits) then first divide the byte into two nibbles.  Thus:-

    111001102   =   1110 01102    =   E 616

    I.e. separately 

    11102 = E16 

    01102    =   616

    Combined, this is E616

    Here are some more examples:-

    01112 

    =
    716

    1110112 

    = 0011 10112 = 3B16
    11011011012  =
    0011 0110 11012
    = 36D16

        
    ~Now try the activity~

     Activity C
    1. Convert the following binary numbers to hexadecimal
    1. 11102
          
    2. 100011110012
     

    Hex to Binary Conversions

    How do we convert a hexadecimal number to binary?  

    The trick is to assign a 4-bit binary number to each hex digit.  Thus:-

    F816  =  1111 10002

    i.e. The first hex number is F. The number F in decimal is 15. When you convert the number 15 to binary you get 1111

    The second hex number is 8. In decimal this is also 8. When you convert the number 8 to binary you get 1000

    Combining the numbers together gives 1111 10002

    The trick is to convert each separate hex number to binary, then join the binary numbers together in the correct order. Also, each separate binary number must be four bits long. If a binary number ends up less than four bits long, just add leading zeros. As an example of this...

    F416  =  1111 01002

    We worked out in the previous example that the number F in binary is 1111. What about the hex number 4? Well, in decimal this is also 4. When you convert the number 4 to binary you get 100. Since this is not four bits long, I just add a leading zero - 0100.

    One final example. Lets convert 7D416 to binary.

    The first hex number is 7. The number 7 in decimal is 7. When you convert the number 7 to binary you get 0111 (notice the leading zero).

    The second hex number is D. In decimal this is 13. When you convert the number 13 to binary you get 1101

    The third hex number is 4. In decimal this is 4. When you convert the number 4 to binary you get 0100

    7D416  =  0111 1101 01002
      

    ~Now try the activity~

     Activity D
    1. Convert the following hexadecimal numbers to binary
    1. F816
         
    2. FF16
     

    Summary

    On completing these notes you should have:-

    • Learnt that the hexadecimal number system uses base 16
    • Practiced converting from hexadecimal to decimal and vice-versa
    • Practiced converting from hexadecimal to binary and vice-versa
     
     

    Site Home

    Top

    Unit Home


       


      

     

     

       
    This Unit 

    Unit Information

    Assessment

    Syllabus

    Scheme of Work

    Learning Resources

    Notes & Lessons

    Assignments

    Quizzes

    Activities

    Resources

    Books & Things

    Links