[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
hexadecimal

Hexadecimal

The hexadecimal numbering system, or base 16, is a numbering system based on the assumption that each digit represents a power of sixteen. These powers begin with 160 (1) immediately to the left of the decimal point, and increase as one moves to the left and decrease as one moves to the right. Thus, the second digit to the left of the decimal represents 161 (16) and the third represents 162 (256).

Obviously, after 9, we run out of standard digits to represent the quantity up to sixteen. The convention is to supply the letters A-F to represent the decimal quantities 10-15 respectively. Thus, the number A would follow 9 (representing decimal 10), B would follow A, up until F (representing decimal 15) and then, using powers of sixteen, the second digit would enter into play.

Thus, the hexadecimal number 10 represents the decimal number 16, and following the quantities, the hexadecimal number 20 represents the decimal number 32.

Each digit, starting with 160 (1) immediately to the left of the decimal and moving towards the left, represents multipliers of the following quantities:

  • 1
  • 16
  • 256
  • 4096
  • 65536
  • 1048576
and so on.

So what? (aka WTF?)

Hexadecimal is used as a compact way to represent bitpatterns, hence it being associated with assembler, though it's actually associated with bitmanipulation and representing bitpatterns in general. In decimal each the bitpattern represented by say the tens digit in 19, overlaps with the bitpattern representing 9. So whenever you want to represent a bitpattern in decimal you have to think about how every digit can effect the pattern. With hexadecimal, each digit has a single independent of every other digit mapping to a bitpattern. Which is
  • 0 = 0000
  • 1 = 0001
  • 2 = 0010
  • 3 = 0011
  • 4 = 0100
  • 5 = 0101
  • 6 = 0110
  • 7 = 0111
  • 8 = 1000
  • 9 = 1001
  • A = 1010 = 10 (note how bits from 9 overlap 10's)
  • B = 1011 = 11
  • C = 1100 = 12
  • D = 1101 = 13
  • E = 1110 = 14
  • F = 1111 = 15
You can also see from this why hexadecimal is used over binary, a 32-bit integer would require 8 hexadecimal values (e.g. 0xDEADBEEF) while it would obviously require 32 bits (e.g. I'm too lazy to type it out).

last edited (December 6, 2002) by Darius, Number of views: 3396, Current Rev: 3 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.