E
Hi,
In diesem Beitrag wurde das auch schon mal behandelt:
http://www.c-plusplus.net/forum/viewtopic.php?t=71870&postdays=0&postorder=asc&start=10const char array[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };std::string ULongTohex(unsigned long data) { unsigned long length = 0; if(data < 0xFF ) length = 2; else if(data < 0xFFFF && length != 2) length = 4; else if(data < 0xFFFFFF && length != 4) length = 6; else if(data < 0xFFFFFFFF && length != 6) length = 8; unsigned int reverse_counter = length; unsigned int *counter = new unsigned int[length]; unsigned int temp = 0; char *hex = new char [length+1]; for (unsigned int i= 0; i < length; i++) { temp = data % 16; data /= 16; data-temp; counter[i] = temp; } for(unsigned int i = 0; i< length ; i++) { hex[--reverse_counter] = (char)array[counter[i]]; } hex[length] = '\0'; std::string ret_val = hex; delete hex; return ret_val; }unsigned%20long%20hexToULong(char%20*data){%20%20unsigned%20hex_length%20=%20std::strlen(data);%20%20unsigned%20long%20return_value%20=%200;%20%20for(unsigned%20int%20i%20=%200;%20i%20%3C%20hex_length;%20i++)%20%20{%20%20%20%20for(unsigned%20char%20j%20=%200;%20j%20%3C%2016;%20j++)%20%20%20%20{%20%20%20%20%20%20if(data[i]%20==%20array[j])%20%20%20%20%20%20%20%20{%20%20%20%20%20%20%20%20%20%20return_value%20=%20((return_value%20*%2016)%20+%20j);%20%20%20%20%20%20%20%20}%20%20%20%20}%20%20}%20%20return%20return_value;}http://www.c-plusplus.net/forum/viewtopic.php?t=71870&postdays=0&postorder=asc&start=10
MfG eV