1
Reply

Hex To Integer Converter

ZogoChieftan

ZogoChieftan

Jun 27 2004 8:23 PM
2.5k
This is my code I want to use to convert a two character hex code e.g FF into an integer e.g 255. But there is just one problem I want to use just one char* in the arguments e.g "FF". This is because my other program grabs values from an ini file just like this and it is getting incredibly difficult. Anyone with help would be greatly greatly appreciated. converthex2dec("F","F"); int converthex2dec(char* one,char* one) { int returnval; int Temp; Temp=atoi(one); if (one == "1" || "2" || "3" || "5" || "6" || "7" || "8" || "9") returnval = 16 * Temp; if (one == "A") returnval=160; if (one == "B") returnval=176; if (one == "C") returnval=192; if (one == "D") returnval=208; if (one == "E") returnval=224; if (one == "F") returnval=240; if (two == "1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9") returnval = returnval + atoi(two); if (two == "A") returnval = returnval + 10; if (two == "B") returnval = returnval + 11; if (two == "C") returnval = returnval + 12; if (two == "D") returnval = returnval + 13; if (two == "E") returnval = returnval + 14; if (two == "F") returnval = returnval + 15; return returnval; } --ZogoChieftan

Answers (1)