Ok just in case it matters this code is for the xbox platform.
I am using the code below to convert a two character hex code e.g: FF into an integer e.g: 255
Earlier I tried it in it's own pc command line platform by putting in the main sub hextodec("FF") and it returned 255 absolutely fine but for some ****** up reason it won't do it here.
int Preset = 0;
int ColourPatch::hextodec(const char* hex)
{
char TempString[5];
strcpy(TempString,"0x");
strcat(TempString,hex);
const char *value = TempString;
struct CHexMap
{
char chr;
int value;
};
const int HexMapL = 16;
CHexMap HexMap[HexMapL] =
{
{'0', 0}, {'1', 1},
{'2', 2}, {'3', 3},
{'4', 4}, {'5', 5},
{'6', 6}, {'7', 7},
{'8', 8}, {'9', 9},
{'A', 10}, {'B', 11},
{'C', 12}, {'D', 13},
{'E', 14}, {'F', 15}
};
char *mstr = _tcsupr(_tcsdup(value));
char *s = mstr;
int result = 0;
if (*s == '0' && *(s + 1) == 'X') s += 2;
bool firsttime = true;
while (*s != '\0')
{
bool found = false;
for (int i = 0; i < HexMapL; i++)
{
if (*s == HexMap[i].chr)
{
if (!firsttime) result <<= 4;
result |= HexMap[i].value;
found = true;
break;
}
}
if (!found) break;
s++;
firsttime = false;
}
free(mstr);
return result; //Returns 0 when I tried it earlier on pc and it returns 255 fine. WTF is going on.
}
void ColourPatch::ReadPreset(char* Location)
{
char Temp[5];
CIniFile iPreset;
char* szSection="ColorData";
iPreset.OpenIniFile(Location);
strcpy(Temp,iPreset.ReadString(szSection,"Preset1","00")); //After this temp equals FF
Preset=hextodec(Temp);
}
Thanks SO SO Much If You Could Shed Some Light Over This
Question
SatansAceN
Hi Again,
Ok just in case it matters this code is for the xbox platform.
I am using the code below to convert a two character hex code e.g: FF into an integer e.g: 255
Earlier I tried it in it's own pc command line platform by putting in the main sub hextodec("FF") and it returned 255 absolutely fine but for some ****** up reason it won't do it here.
int Preset = 0; int ColourPatch::hextodec(const char* hex) { char TempString[5]; strcpy(TempString,"0x"); strcat(TempString,hex); const char *value = TempString; struct CHexMap { char chr; int value; }; const int HexMapL = 16; CHexMap HexMap[HexMapL] = { {'0', 0}, {'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5}, {'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'A', 10}, {'B', 11}, {'C', 12}, {'D', 13}, {'E', 14}, {'F', 15} }; char *mstr = _tcsupr(_tcsdup(value)); char *s = mstr; int result = 0; if (*s == '0' && *(s + 1) == 'X') s += 2; bool firsttime = true; while (*s != '\0') { bool found = false; for (int i = 0; i < HexMapL; i++) { if (*s == HexMap[i].chr) { if (!firsttime) result <<= 4; result |= HexMap[i].value; found = true; break; } } if (!found) break; s++; firsttime = false; } free(mstr); return result; //Returns 0 when I tried it earlier on pc and it returns 255 fine. WTF is going on. } void ColourPatch::ReadPreset(char* Location) { char Temp[5]; CIniFile iPreset; char* szSection="ColorData"; iPreset.OpenIniFile(Location); strcpy(Temp,iPreset.ReadString(szSection,"Preset1","00")); //After this temp equals FF Preset=hextodec(Temp); }Thanks SO SO Much If You Could Shed Some Light Over This
From ZogoChieftan
Link to comment
Share on other sites
0 answers to this question
Recommended Posts