Thread: Hexadecimal

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    361

    Hexadecimal

    I was wondering if anyone here could give me a good site that teaches me hexadecimal that I often see in code.

    I looked on the FAQ board and that didn't have anything so I hope I didn't miss a post here that had it.

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    There's not much to teach about hexadecimal. It basically has 16 characters, 0 to F. Good links can be made between hex and binary, for example:

    1d=1h (1 decimal = 1 hex)
    2d=2h
    4d=4h
    8d=8h
    16d=10h
    32d=20h
    64d=40h (64 decimal = 40 hex)
    128d=80h

    As you can see, the binary series translates well into hex. For that reason, people often use hex to represent things that are related to binary.

    What exactly do you want to know about hexadecimal? If you just want to convert from one system to the other, use calc.exe.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    26
    Decimal Hex
    1 1
    2 2
    3 3
    4 4
    5 5
    6 6
    7 7
    8 8
    9 9
    10 A
    11 b (yes theres a reason why its not caps)
    12 C
    13 d
    14 E
    15 F
    16 10
    17 11
    18 12

    It keeps going on from there. Basically you just have to know that each "power of" is to 16 instead of 10, just as binary is a power of 2 for each place. As for the reason why its not in caps, it usually doesn't matter in programming but in electronics in 7 segment LCD displays you can only display b and d in lowercase otherwise they would look like 8 and 0.

  4. #4
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    EDIT:: I'M GOING BLIND!
    Last edited by axon; 09-28-2003 at 07:57 PM.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  5. #5
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    He did explain, axon.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  6. #6
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    decimal = base ten:
    Code:
    1 = 10^0 
    2 = 10^0*2
    ...
    10 = 10^1 
    20 = 10^1*2
    21 = 10^1*2 + 10^0
    ...
    So hex is base 16 therefore there are 16 numerals: 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f

    And each digit represents a power of 16:
    Code:
    1 = 16^0 (1 in decimal)
    ...
    10 = 16^1 (16 in decimal)
    ...
    The same goes for binary. Base 2, so only two numerals (0,1) and each digit is a power of two...so 1101 is 13 (2^0 + 2^2 + 2^3)
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  7. #7
    Registered User
    Join Date
    Jan 2003
    Posts
    361
    [code]0xbd0e8406, 0xfb56, 0x4322, 0x8b, 0xc6, 0xbd, 0x6e, 0x48, 0x1f, 0x55, 0x64[code]

    In that example what does the 0x mean?

    Is that to identify it is using hex now or what?

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Is that to identify it is using hex now
    Yes.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Random hexadecimal comments...

    As bennyandthejets said, Hex is used as an alternative to binary. Everything inside the compurer is done and stored in binary.

    Hex is most-often used when the number is being used as a bit-pattern rather than "just a number." So, you would generally be using bitwise operations with hex... It is rare to use addition & subtraction, etc. It is also quite common to use hex for addresses. ...So, you might use addition and subtraction with hex addresses.

    There are two reasons for avoiding the direct use of binary - When you get beyond one byte (8-bits), binary gets difficult to read... you have to start counting bits. And, it's not easy to use binary directly in C / C++... You can't use binary in your source code.

    The reason that hex is used in place of decimal, is that it is much easier to convert between binary and hex than between binary and decimal. If you learn 14 conversions (you already know zero and one), you can convert numbers of any size in your head!

    The built-in Windows calculator can convert between hex/decimal/octal/binary.
    Start->Programs->Accessories->Calculator->Scientific->Hex.

    The 0x notation is to tell the C / C++ compiler that the number is hex. Different computer languages use different notation.

    Good try on the code tags... you forgot the slash in the closing tag [/code].
    Last edited by DougDbug; 09-29-2003 at 02:01 PM.

  10. #10
    Registered User
    Join Date
    Jan 2003
    Posts
    361
    Thank you all, I now understand hexidecimal.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 12-02-2007, 05:55 AM
  2. hexadecimal to ascii
    By jpablo in forum C Programming
    Replies: 2
    Last Post: 04-12-2006, 05:28 PM
  3. would you explain to me? hexadecimal to decimal
    By shteo83 in forum C Programming
    Replies: 2
    Last Post: 02-25-2006, 03:55 PM
  4. hexadecimal
    By pierremk in forum C++ Programming
    Replies: 2
    Last Post: 03-12-2002, 08:05 PM
  5. decimal to binary, decimal to hexadecimal and vice versa
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 12-08-2001, 11:07 PM