home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / texts / txtfiles_misc / numberbases.text < prev    next >
Text File  |  1995-07-10  |  10KB  |  294 lines

  1. #DATA $NAME "An Introduction to Number Bases" / $AUTHOR "Light Ray" / $VERSION 001 / $DATE  950709 / $TYPE  { TEXT ASCII CRLF } #DATA
  2.  
  3.           ********************************************************
  4.  
  5.                                An Introduction To                                
  6.  
  7.                                  NUMBER BASES
  8.  
  9.                                      by
  10.  
  11.                                   Light Ray
  12.  
  13.           ********************************************************
  14.  
  15.   PREREQUISITE: A Brain
  16.  
  17.   ---------------------------------
  18.   Notes
  19.   ---------------------------------
  20.  
  21.   This is taken from the "lab notes" from Explorer Post 340, the oldest
  22.   Boy Scout Explorer Post in the world, as far as I know.  Explorer Post
  23.   340 is wonderful.  We meet at the Western Digital Building in the
  24.   El Toro "Y", between the I-5 and 405 ("San Diego") freeways every
  25.   Wednesday night from about 7:15pm to around 9:30pm.
  26.  
  27.   A knowledge of alternate number bases (namely binary, hexidecimal,
  28.   and sometimes octal) is necessary for advanced programming, digital
  29.   logic design, impressing your friends, winning the lottery, and
  30.   having a successful and fullfilling life..  Well, almost all of
  31.   those.
  32.  
  33.   You should memorize the 16 possible binary nibbles and their 
  34.   corresponding values in decimal and hexidecimal, though you will
  35.   do this automatically if you continue to use them frequently.
  36.   You'll probably be saying, "Yeah, I am 010010 years old and I
  37.   got my car in the year 07C9, A.D." by the time you finish reading 
  38.   this...
  39.  
  40.   BTW, this is the first file in a series.
  41.  
  42.   ---------------------------------
  43.   Introduction
  44.   ---------------------------------
  45.  
  46.   In base X, there are X symbols.  People currently use base ten just
  47.   about everywhere, supposedly because people have ten fingers.  Well,
  48.   most people do, except for those of us who take interest in machining
  49.   or pyrotechnics.
  50.  
  51.   Bases other than the ever present base-10 have more or fewer symbols
  52.   making them more applicable for non-human applications, those that
  53.   do not have ten fingers.
  54.  
  55.   ---------------------------------
  56.   A Summary Of Base 10
  57.   ---------------------------------
  58.  
  59.   Base 10 (decimal) uses 10 symbols.  These are 0, 1, 2, 3, 4, 5, 6, 7,
  60.   8, and 9.  This is why it is called base 10.
  61.  
  62.   When writing a number in a specific base, the base is written in
  63.   subscript after the number.  Since I can't do subscript in ASCII
  64.   text, I am the base in perenthesis:  13(base 10)
  65.  
  66.   To count in base 10, we start at 0 and add one until we get to 9.  At
  67.   this point, it is necessary to create an addittional column to the left,
  68.   containing a one.  Every time the first column reaches 9, it is set to
  69.   zero and the column to the left is incremented.  When 99 is reached a
  70.   third column containing a one is created and the two nines are set to
  71.   zero, etc.
  72.  
  73.   In base 10, every column is 10 times greater than the column to the
  74.   right:
  75.  
  76.         thousands       hundreds        tens            ones
  77.  
  78.          10^3             10^2          10^1            10^0
  79.  
  80.   [The carrot symbol (^) denotes "to the power of"]
  81.  
  82.   The value of the number 1234 in base 10 is computed by multiplying
  83.   each digit by the value of its place and taking the sum of the
  84.   individual products.
  85.  
  86.     1234(base 10)  = (1 * 10^3) + (2 * 10^2) + (3 * 10^1) + (4 * 10^0)
  87.     1234(base 10)  = (1 * 1000) + (2 * 100)  + (3 * 10)  +  (4 * 1)
  88.     1234(base 10)  = 1000 + 200 + 30 + 4
  89.     1234(base 10)  = 1234(base 10)
  90.  
  91.   [An asterik symbol (*) denotes "multiplied by"]
  92.  
  93.   The range of positive values that can be represented by n digits in
  94.   base x is 0 to (x^n - 1).  For example, the range of positive values
  95.   that may be expressed by a ten digit number in base four is 0 to
  96.   9999.
  97.  
  98.     x = 10
  99.     n = 4
  100.     range = 0 to (x^n - 1)
  101.     range = 0 to (10^4 - 1)
  102.     range = 0 to (10000 - 1)
  103.     range = 0 to 9999
  104.  
  105.   ---------------------------------
  106.   A Summary Of Base 2
  107.   ---------------------------------
  108.  
  109.   Base Two, otherwise known as Binary, uses TWO symbols.  These two
  110.   symbols are ZERO (0) and ONE (1).  In binary, the symbols 2,3,4 etc
  111.   do not exist.
  112.  
  113.   Binary is often used in digital electronics and logic because a digital
  114.   signal has two states, on (1) and off (0).  On is usually five volts and
  115.   off is usually ground or zero volts.
  116.  
  117.   To count in base two, use the same system as base ten.  However, you only
  118.   have two symbols.
  119.  
  120.   Start at Zero.
  121.  
  122.   To find the next number, increment the first (right-most) digit.  If this
  123.   digit is already a ONE, then change it to a ZERO and increment the value
  124.   to the left.
  125.  
  126.   Base 2        Base 10
  127.  (binary)       (decimal)
  128.    0000           00
  129.    0001           01
  130.    0010           02
  131.    0011           03
  132.    0100           04
  133.    0101           05
  134.    0110           06
  135.    0111           07
  136.    1000           08
  137.    1001           09
  138.    1010           10
  139.    1011           11
  140.    1100           12
  141.    1101           13
  142.    1110           14
  143.    1111           15
  144.  
  145.    In base two, every column has two times greater value than the
  146.    column immediately to the right.
  147.  
  148.          eights         fours           twos            ones
  149.           2^3            2^2             2^1             2^0
  150.  
  151.    The value of the number 1101 in base 2 is computed by multiplying
  152.    each digit by the value of its column and summing the individual
  153.    products.
  154.  
  155.     1101(base 2)  =  (1 * 2^3) + (1 * 2^2) + (0 * 2^1) + (1 * 2^0)
  156.     1101(base 2)  =  (1 * 8)   + (1 * 4)   + (0 * 2)   + (1 * 1)
  157.     1101(base 2)  =  (8)       + (4)       + (0)       + (1)
  158.     1101(base 2)  =  13(base 10)
  159.  
  160.    The range of positive values that can be expressed by n digits in
  161.    base two is zero through (2^n - 1).  For example, the numbers 0
  162.    through (2^4 - 1) or 15 may be expressed in four digits of binary.
  163.  
  164.    A BIT is a single Binary digIT.  A bit is either zero or one.
  165.  
  166.    A NIBBLE is four bits.
  167.  
  168.    A BYTE is two nibbles or eight bits.  A byte has a value of
  169.    zero to (2^8 - 1) or 255.
  170.  
  171.    A WORD is NORMALLY two bytes.  A word can express 0 to 65535.
  172.  
  173.    A LONG WORD is NORMALLY two words.
  174.  
  175.    An 80386 processor transfers digital data a word at a time.
  176.    A 486 processor transfers data a long word at a time.
  177.  
  178.   ---------------------------------
  179.   A Summary Of Base 16
  180.   ---------------------------------
  181.  
  182.    Base 16 is known as hexidecimal.  Hexidecimal uses sixteen symbols,
  183.    which are: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
  184.  
  185.    Keep in mind that:  A(base 16) = 10(base 10)
  186.                        B(base 16) = 11(base 10)
  187.                        etc.
  188.  
  189.    The place values in hexidecimal are:
  190.  
  191.         4096s   256s    16s     ones
  192.         16^3    16^2    16^1    16^0
  193.  
  194.   Sample Conversion:
  195.  
  196.    1A3F(base 16) = (1 * 16^3) + (A * 16^2) + (3 * 16^1) + (F * 16^0)
  197.    1A3F(base 16) = (1 * 4906) + (10 * 256) + (3 * 16)   + (15 * 1)
  198.    1A3F(base 16) = 4906       + 2560       + 48         + 15
  199.    1A3F(base 16) = 6719(base 10)
  200.  
  201.  
  202.   ---------------------------------
  203.   Converting from Decimal to Binary
  204.   ---------------------------------
  205.  
  206.   The best way to illustrate how to convert a decimal number to binary
  207.   (or any other base for that matter) is to show an example.
  208.  
  209.   Say that we want to convert 197(decimal) to binary.
  210.  
  211.   First, write out the place values for the target base.  Start with a
  212.   place value that is greater than the number you wish to convert.
  213.   
  214.   256 128 064 032 016 008 004 002 001
  215.   2^8 2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0
  216.  
  217.   The object is to come up with 197 by taking the sum of selected place
  218.   values.  Those place values that are selected will be "1" and those that
  219.   aren't will be set to "0".
  220.  
  221.   For example, 197 is
  222.       
  223.   128 + 64 + 4 + 1
  224.  
  225.   So we write 1's under the 128, 64, 4, and 1 columns, and 0's under the
  226.   other columns:
  227.  
  228.   256 128 064 032 016 008 004 002 001
  229.     0   1   1   0   0   0   1   0   1
  230.  
  231.  
  232.   The answer is 11000101(base 2).
  233.  
  234.   There is an easier way, but I don't remember it right now. (=
  235.  
  236.   ---------------------------------
  237.    Converting from Hexidecimal to
  238.    Binary and back.
  239.   ---------------------------------
  240.  
  241.    The range that may be expressed by one binary nibble is 0 to 15.
  242.    Incidentally, one Hexidecimal digit has the same range, 0 to 15.
  243.  
  244.    Handy conversion chart:
  245.  
  246.   Base 2        Base 10       Base 16 
  247.  (binary)       (decimal)     ("hex")
  248.    0000           00            0
  249.    0001           01            1
  250.    0010           02            2
  251.    0011           03            3
  252.    0100           04            4
  253.    0101           05            5
  254.    0110           06            6
  255.    0111           07            7
  256.    1000           08            8
  257.    1001           09            9
  258.    1010           10            A
  259.    1011           11            B
  260.    1100           12            C
  261.    1101           13            D
  262.    1110           14            E
  263.    1111           15            F
  264.   
  265.    To convert 0100100101110110(base 2) to hexidecimal, first split it
  266.    up into nibbles:
  267.  
  268.    0100 1001 0111 0110
  269.   
  270.    Then, convert each nibble to hex.  Use the chart if necessary.
  271.  
  272.    binary:  0100 1001 0111 0110
  273.    hex:     4    9    7    6
  274.  
  275.    Thus, 0100100101110110(base 2) = 4976(base 16)
  276.  
  277.    Since the base 16 version is so much shorter, we work with
  278.    hex very often when programming and using digital logic.
  279.  
  280.   ---------------------------------
  281.    END
  282.   ---------------------------------
  283.  
  284.   This was typed and editted by Light Ray at the Digital Forest BBS,
  285.   which may be reached at +1 (714) 586-6142.  It is located in 
  286.   Mission Viejo, California, United States of America.  This document
  287.   is based on Explorer Post 340 "lab notes" by "rlh" dated 5/10/95.
  288.   Please send any comments, suggestions, compaints, or addittions to
  289.   me at dr261@cleveland.freenet.edu, even if all you say is "I read
  290.   your file."  I may also be reached at 1:103/925, 66:714/10, or
  291.   50:100/505.
  292.  
  293.   Light Ray
  294.