Home Previous section Next section

Numbering systems


(This chapter is provided to help you understand certain parts of chapter 19, Memory.)

Normally, when we use a number such as 110, we understand it to mean "one hundred and ten," but in this chapter you will see how this is not always the case.


Hexadecimal numbers

We generally use the base 10 (decimal) numbering system, where each digit must be between 0-9; but the "hexadecimal" system (base 16) can also have digits A, B, C, D, E, and F (16 total digits).

(The hexadecimal numbers in this tutorial are red.)

    0 = Zero
    1 = One
    2 = Two
    3 = Three
    4 = Four
    5 = Five
    6 = Six
    7 = Seven
    8 = Eight
    9 = Nine
    A = Ten
    B = Eleven
    C = Twelve
    D = Thirteen
    E = Fourteen
    F = Fifteen
In the base 10 system, you add another digit when you get past the number 9; but with base 16, it isn't added until after F (or fifteen).
    10 = Sixteen
    11 = Seventeen
    12 = Eighteen
    13 = Nineteen
    14 = Twenty
    15 = Twenty one
    16 = Twenty two
    17 = Twenty three
    18 = Twenty four
    19 = Twenty five
    1A = Twenty six
    1B = Twenty seven
    1C = Twenty eight
    1D = Twenty nine
    1E = Thirty
    1F = Thirty one
    20 = Thirty two
    21 = Thirty three
    22 = Thirty four
    23 = Thirty five
    24 = Thirty six
     .
     .
     .
In the decimal system (base 10), we multiply ten for each time a digit goes to the left.
       10 = 10
      100 = 10 * 10
     1000 = 10 * 10 * 10
    10000 = 10 * 10 * 10 * 10
        .
        .
        .
But in the hexadecimal (base 16) system, we multiply sixteen, instead.
       10 = 16                 (16)
      100 = 16 * 16            (256)
     1000 = 16 * 16 * 16       (4096)
    10000 = 16 * 16 * 16 * 16  (65536)
        .
        .
        .
Therefore, since 10 is 16 and 100 is 256, the number 110 is two hundred and seventy two (272).

    110 = (100 + 10) = (256 + 16) = 272
(To download a number converter, click here.)


TIP: To enter a hexadecimal number in QBasic, use &H.

&H110



Binary numbers

The "binary" system (base 2) can only have two digits, 0 and 1. Therefore, no binary number has a digit between 2 and 9.

(Binary numbers are shown in dark blue.)
        0 = Zero
        1 = One
       10 = Two
       11 = Three
      100 = Four
      101 = Five
      110 = Six
      111 = Seven
     1000 = Eight
     1001 = Nine
     1010 = Ten
     1011 = Eleven
     1100 = Twelve
     1101 = Thirteen
     1110 = Fourteen
     1111 = Fifteen
    10000 = Sixteen
    10001 = Seventeen
    10010 = Eighteen
    10011 = Nineteen
    10100 = Twenty
        .
        .
        .
Notice how binary numbers can be found by excluding numbers that have a 2, 3, 4, 5, 6, 7, 8, or 9.
       0
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
       .
       .
       .
      97
      98
      99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
       .
       .
       .
In base 10, as explained above, we multiply ten for each time a digit goes to the left.
       10 = 10
      100 = 10 * 10
     1000 = 10 * 10 * 10
    10000 = 10 * 10 * 10 * 10
        .
        .
        .
But in binary, we multiply by two.
       10 = 2              (2)
      100 = 2 * 2          (4)
     1000 = 2 * 2 * 2      (8)
    10000 = 2 * 2 * 2 * 2  (16)
        .
        .
        .
So, since 10 is 2 and 100 is 4, the number 110 is six.

    110 = (10 + 100) = (2 + 4) = 6
(To download a number converter, click here.)


TIP: Binary (and hexadecimal) numbers are often written with leading 0's.

0000  (same as 0
0001  (same as 1
0010  (same as 10)
0011  (same as 11)



Next section


Feel free to distribute this tutorial, upload it to your website, link to it from your site, etc.

http://www.geocities.com/progsharehouse/qbtutor
Mirror: http://development.freeservers.com/qbtutor