# HEX Values?

• 02-05-2002
OneStiffRod
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.
• 02-05-2002
golfinguy4
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.
• 02-05-2002
OneStiffRod
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 ???
• 02-05-2002
SilentStrike
Yeah.. should be 1*16^4, he just made a mistake when typing it.
• 02-05-2002
swoopy
>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).
• 02-07-2002
golfinguy4
I did make a typo. I was using the number key on the right and missed typed.