Interview Question

Interview(Student Candidate) Pittsburgh, PA

transfer the string hexadecimal number "f3a6.123f" into

  decimal number.
Answer

Interview Answer

1 Answer

0

1. Need a hex to decimal lookup table (e.g. java hashmap). 2. Convert string to char[]. 3. Find the location of decimal point 'K'. double result; char[] data; // input for(i = K-1; i >= 0,; i--){ result += lookup.get(data[i])*Math.pow(16,K-1-i); } for(i=K+1; i<data.length; i++){ result += lookup.get(data[i])*Math.pow(16,-(i-K)); } return result; I haven't tested this, so test if before you use it.

Anonymous on Nov 12, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.