Comment puis-je entrer DEADBEEF
et sortir DE
DEADBEEF
BE
EF
sous forme de tableaux de quatre octets?
void hexconvert( char *text, unsigned char bytes[] ) { int i; int temp; for( i = 0; i < 4; ++i ) { sscanf( text + 2 * i, "%2x", &temp ); bytes[i] = temp; } }
On dirait que vous voulez parsingr une chaîne au format hexadécimal dans un entier. La manière C ++:
#include #include #include template IntType hex_to_integer(const std::ssortingng& pStr) { std::ssortingngstream ss(pStr); IntType i; ss >> std::hex >> i; return i; } int main(void) { std::ssortingng s = "DEADBEEF"; unsigned n = hex_to_integer(s); std::cout << n << std::endl; }