Dear friends, I am trying to write a function that will convert an integer to a hex string. I would like to use the switch method. The code below is my work in progress, the logic i'm trying to follow is:
take the decimal integer 'n' and divide by 16
the remainder 'm' will form the first hex digit - hexstring[]
I want to use '0' to represent '1', '1' to represent 'A" and on until remainder 15 (F).
Then i want to take the quotient and divide by 16 and the remainder will form the second hex digit, next to last.
i want to repeat this process until my string is filled up and if it stop with a quotient equal to 0, fill the rest of the hex string with '0'.
could someone help me with my syntax, when I pass on a decimal i have an invalid digit "8" in octal constantCode:int itox( char hexstring[], int n) { int m, b, flag; b = (m / 16); m = m - (b * 16); for (m = 0;m > 0; m++) switch (m) { case '1' : m = 01; break; case '2' : m = 02; break; case '3' : m = 03; break; case '4' : m = 04; break; case '5' : m = 05; break; case '6' : m = 06; break; case '7' : m = 07; break; case '8' : m = 08; break; case '9' : m = 09; break; case '10' : m = A; break; case '11' : m = B; break; case '12' : m = C; break; case '13' : m = D; break; case '14' : m = E; break; case '15' : m = F: break; default: flag = 0; break; } return (hexstring[m++]); } }