Hexadecimal Numbers etc?

This is a discussion on Hexadecimal Numbers etc? within the C++ Programming forums, part of the General Programming Boards category; Hi Everyone, I am really confused about hexadecimal numbers, and I feel it's holding me back from continuing to learn ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    18

    Question Hexadecimal Numbers etc?

    Hi Everyone,

    I am really confused about hexadecimal numbers, and I feel it's holding me back from continuing to learn C++.

    So, in C++ For Dummies, it says this:

    123 to the power of 10, becomes 7B to the power of 16.
    I really don't understand how 7B to the power of 16 appears as 123 to the computer.

    Any idea's?

    Many thanks.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,725
    Quote Originally Posted by sharkbate24
    I am really confused about hexadecimal numbers, and I feel it's holding me back from continuing to learn C++.
    Well, there are many areas of C++ that have nothing or little to do with hexadecimal numbers, so you really should not feel that way

    Nonetheless, search the Web for "hexadecimal" or "hexadecimal representation".

    Quote Originally Posted by sharkbate24
    I really don't understand how 7B to the power of 16 appears as 123 to the computer.
    It arguably appears as neither 7B nor 123 to the computer, but as a number in binary representation.

    7B in base 16 = 7 * 16 + 11 = 123 in base 10
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    18
    Quote Originally Posted by laserlight View Post
    Well, there are many areas of C++ that have nothing or little to do with hexadecimal numbers, so you really should not feel that way

    Nonetheless, search the Web for "hexadecimal" or "hexadecimal representation".


    It arguably appears as neither 7B nor 123 to the computer, but as a number in binary representation.

    7B in base 16 = 7 * 16 + 11 = 123 in base 10
    Wow, you're clever hehe. I would never be able to work that out.

    Thanks .

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    If you understand decimal then you understand hexadecimal.

    In decimal we have the one's place, the ten's place, the hundred's place, etc.

    In hex we have the one's place, the sixteen's place, the 256's place, etc.

    In decimal, each "place" is bigger by a factor of ten. In hex, by a factor of sixteen.

    The problem is we only have ten Arabic numerals, but we have to represent sixteen digits, so we use the six letters A, B, C, D, E, F for the excess.

    Given this, does Laserlight's calculation make any more sense?

    7B -- in the one's place there is a 'B', which is eleven. In the sixteen's place is a 7. So you have seven sixteens, which is 112. Plus another eleven, which is 123.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    18
    Quote Originally Posted by brewbuck View Post
    If you understand decimal then you understand hexadecimal.

    In decimal we have the one's place, the ten's place, the hundred's place, etc.

    In hex we have the one's place, the sixteen's place, the 256's place, etc.

    In decimal, each "place" is bigger by a factor of ten. In hex, by a factor of sixteen.

    The problem is we only have ten Arabic numerals, but we have to represent sixteen digits, so we use the six letters A, B, C, D, E, F for the excess.

    Given this, does Laserlight's calculation make any more sense?

    7B -- in the one's place there is a 'B', which is eleven. In the sixteen's place is a 7. So you have seven sixteens, which is 112. Plus another eleven, which is 123.
    Aah, that's really cleared things up, thanks a lot.

    But I don't quite understand how we know if it's an Hexadecimal Number, or another one, such as Octadecimal number?

    Thanks a lot.

  6. #6
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by sharkbate24 View Post
    But I don't quite understand how we know if it's an Hexadecimal Number, or another one,
    If the number is an integer literal appearing in c or c++ code we know.
    if it starts with 0x it's hex, if it starts with 0 it's octal anything else is decimal.
    Kurt

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by sharkbate24 View Post
    Aah, that's really cleared things up, thanks a lot.

    But I don't quite understand how we know if it's an Hexadecimal Number, or another one, such as Octadecimal number?

    Thanks a lot.
    You can't. 10 can have an infinite number of values, depending on it's base. However, we people agreed that base 10 is the usual, so unless otherwise specified, 10 will be just that.. "10". in decimal.
    How to indicate depends on who you want to inform the base. If it's a human, you'll just write it down. A compiler will decide on the number itself. Usually, "0x" is prepended to make it a hexadecimal number, while a "0" is prepended to make it octal.
    So 010 = 8
    0x10 = 16

    I've seen it differ sometimes though. Some compilers use "10h" to indicate hex, and a b to indicate binary.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing unique numbers to an array
    By yardy in forum C Programming
    Replies: 6
    Last Post: 12-27-2006, 08:15 PM
  2. Comparing numbers to a list of numbers held in a text file
    By jmajeremy in forum C++ Programming
    Replies: 3
    Last Post: 11-06-2006, 06:56 AM
  3. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  4. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 10:15 AM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 05:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21