HEX Values?

This is a discussion on HEX Values? within the C++ Programming forums, part of the General Programming Boards category; I'm taking some advanced level tests and there are some questions that ask you to give the result of a ...

  1. #1
    UNBANNED OneStiffRod's Avatar
    Join Date
    Jan 2002
    Posts
    669

    HEX Values?

    I'm taking some advanced level tests and there are some questions that ask you to give the result of a function would give under some circumstances.

    1. double tstFXN() {
    double result;
    double N = 0x003F;
    int x = 5;

    result = x + N;
    return result;
    }

    What is the value of result:? A) B) C) D)

    //This is not an actual question from the test but gives the jist of what type of question they ask.

    The problem I'm having is how can I understand what the hex value is by looking at it, what calculations do I need to do to get the result of the hex value. I know it's base 16 for hex values but how do I apply this to get the value? I'm taking the test without any computer compiler support so it's all in my head calcs.

    Any help appreciated.

    BTW, this exam is for the MCSD and not school work.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    0x12345 equals 5*16^0+4*16^1+3*16^2+2*16^3+1*16^1


    Basically, count the digits from the right, subtract one from the digit number, and then multiply that digit times the base raised to the digit number - 1 power.

  3. #3
    UNBANNED OneStiffRod's Avatar
    Join Date
    Jan 2002
    Posts
    669
    How come the last position is 1*16^1, shouldn't it be ^4???

    and could you tell me what the final number value is since this test question is also given in reverse.

    is the final value: 25165824 ???
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  4. #4
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Yeah.. should be 1*16^4, he just made a mistake when typing it.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >is the final value: 25165824 ???

    0x12345 equals 74565 decimal.

    By the way, if you have a windows computer, the calculator application will convert between hex and decimal (in scientific mode).

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    I did make a typo. I was using the number key on the right and missed typed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. putting values into an array
    By zdream8 in forum C Programming
    Replies: 15
    Last Post: 05-22-2008, 12:18 AM
  2. Need help with project
    By chrisa777 in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2006, 06:01 PM
  3. adding ASCII values
    By watshamacalit in forum C Programming
    Replies: 1
    Last Post: 12-26-2002, 07:16 PM
  4. How to read in empty values into array from input file
    By wpr101 in forum C++ Programming
    Replies: 5
    Last Post: 11-28-2002, 10:59 PM
  5. Replies: 1
    Last Post: 04-05-2002, 11:19 AM

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