Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Peter Norton Programmer's Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

  Bits and Hexadecimal

  Segmented Addresses and Hexadecimal Notation

  Decimal-Hexadecimal Conversion

  Using BASIC for Hex Arithmetic

  Hex Addition

  Hex Multiplication

  Hexadecimal numbers crop up in computer work for the simple reason that
  everything a computer does is based on binary numbers, and hexadecimal
  notation is a convenient way to represent binary numbers.

  Hexadecimal numbers are built on a base of 16, exactly as ordinary decimal
  numbers are built on a base of 10; the difference is that hex numbers are
  written with 16 symbols whereas decimal numbers are written with 10
  symbols (0 through 9). (From here on, we'll use the terms "hexadecimal"
  and "hex" interchangeably.) In hex notation, the symbols 0 through 9
  represent the values 0 through 9, and the symbols A through F represent
  the values 10 through 15. (See Figure B-1.) The hex digits A through F
  are usually written with capital letters, but you may also see them with
  the lowercase letters a through f; the meaning is the same.

  Hex numbers are built out of hex digits the same way that decimal numbers
  are built. For example, when we write the decimal number 123, we mean the
  following:

      1 times   100  (10 times 10)
    + 2 times    10
    + 3 times     1

  If we use the symbols 123 as a hex number, we mean the following:

      1 times   256  (16 times 16)
    + 2 times    16
    + 3 times     1

  There does not seem to be a standard way to write hex numbers, and you may
  find them expressed differently in different places. BASIC uses the prefix
  &H to identify hex numbers, and this notation is sometimes used elsewhere,
  as well. In C, hexadecimal numbers start with the characters 0x (zero
  followed by lowercase x). Occasionally, the prefix # or 16# is used, but
  more often (and throughout this book) a hex number is simply followed by
  an upper- or lowercase H. Another common way to express hex numbers,
  especially in reference information, is without any special notation at
  all. You are expected to understand from the context when a number is
  written in decimal notation and when it is written in hex. When you see a
  number in any technical reference information that seems to be a decimal
  number, check carefully; it may actually be in hex.

  Hex                      Dec
  --------------------------------------------------------------------------
  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
  --------------------------------------------------------------------------

  Figure B-1.  The decimal value of the 16 hex digits.

  When you need to work with hex numbers, you can use interpreted BASIC as
  an aid (see page 445), or you can work with them by hand. Whichever
  method you choose, you may find the conversion and arithmetic tables
  located toward the end of this appendix helpful. But before we get to the
  tables, we'll first explain why hex numbers and binary numbers are so
  compatible. Then we'll describe one of the most common uses of hex numbers
  in PC and PS/2 programming: segmented addressing.

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson