So my class assignment is to make our own algorithm not using the built in functions that converts an int to hexidecimal and for the life of me it will not comply.
The example in our text converts 24032 to 0x5DE0 but what I am getting as output is 3210.
This is my code
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List<string> errorList = new List<string>();
List<int> hexList = new List<int>();
string intInput = "";
string msgOutput = "";
private void btn_Hex_Click(object sender, EventArgs e)
{
intInput = box_Int.Text;
int toHexFunc = Validator(intInput);
ToHex(toHexFunc);
}
public void ToHex(int fromHexBtn)
{
int n = fromHexBtn;
char[] hexNum = new char[100];
int i = 0;
while (n != 0)
{
int iterTemp = n % 16;
// using ASCII table from https://www.dotnetperls.com/ascii-table
if (iterTemp < 10)
{
hexNum[i] = (char)(iterTemp + 48);
i++;
}
else
{
hexNum[i] = (char)(iterTemp + 55);
i++;
}
n = n / 16;
}
for (int j = i - 1; j >= 0; j--)
{
hexList.Add(j);
}
msgOutput = String.Join("", hexList);
lbl_Message.Text = msgOutput;
}
}