# Please someone fix this code

I'm trying to convert numbers.. The first method works great. but the second one doesnt:

/// <summary>
/// Convert an integer value to hex
/// </summary>
/// <param name="number">Accepts an integer number</param>
/// <returns>String Hex value</returns>
public static String base10to16(int number)
{
String[] hexnumbers = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"};
String hex = "";
int remainder;
do
{
remainder = number % 16;
number = number / 16;
hex = hexnumbers[remainder] + hex;
} while (number>0);
return hex;
}

/// <summary>
/// Converts a hex number to integer
/// </summary>
/// <param name="input">Accepts a String</param>
/// <returns>Integer value</returns>
public static int base16to10(string input)
{
string hexnumbers = "0123456789ABCDEF";
int number = 0;
for (int i= 0;i<input.Length;i++)
{
number *= 16;
number += hexnumbers.IndexOf(input[i]);
}
return number;
}
LVL 3
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
input = input.ToUpper();
in base16to10()?
Freelance IT ConsultantCommented:
You forgot that the order of the Hex string is right to left so base16to10() must be written like :

public static int base16to10(string input)
{
string hexnumbers = "0123456789ABCDEF";
int number = 0;
for (int i = input.Length;i>0;i--)
{
number *= 16;
number += hexnumbers.IndexOf(input[i-1]);
}
return number;
}

Experts Exchange Solution brought to you by