Comment puis-je entrer DEADBEEF
et afficher DE
BE
EF
comme tableaux de quatre octets?chaîne au tableau d'octets
1
A
Répondre
4
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;
}
}
+0
Merci. C'est du travail. – hlgl
2
Semble que vous voulez analyser une chaîne hexadécimale en un nombre entier. Le chemin C++:
#include <iostream>
#include <sstream>
#include <string>
template <typename IntType>
IntType hex_to_integer(const std::string& pStr)
{
std::stringstream ss(pStr);
IntType i;
ss >> std::hex >> i;
return i;
}
int main(void)
{
std::string s = "DEADBEEF";
unsigned n = hex_to_integer<unsigned>(s);
std::cout << n << std::endl;
}
Questions connexes
- 1. Chaîne au tableau d'octets bruts
- 2. Chaîne csv de Python au tableau
- 3. déclarer ou convertir une chaîne au format de tableau PHP
- 4. Ajouter une chaîne au tableau de caractères dans C
- 5. Comment accéder à une chaîne au format de tableau JSON
- 6. ajouter une chaîne au début de chaque entrée de tableau
- 7. C Tableau de chaîne
- 8. Chaîne entre un tableau?
- 9. Tableau Java: accès direct au composant dans le tableau
- 10. Tableau chaîne et un paramètre de chaîne
- 11. Comment ajouter au tableau
- 12. LINQ au tableau
- 13. smarty attribuer au tableau
- 14. preg_match au tableau. PHP
- 15. Tableau d'index au tableau de gammes
- 16. Attribuer un tableau de pointeurs au tableau
- 17. chaîne au nombre
- 18. Convertir un tableau en chaîne
- 19. comparer chaîne en php tableau
- 20. Tableau cacao d'objets à chaîne
- 21. chaîne convertir en tableau multidimensionnel
- 22. de tableau JavaScript à chaîne
- 23. Tableau multidimensionnel dans la chaîne
- 24. comment créer chaîne de tableau
- 25. chaîne inverse sans nouveau tableau
- 26. Chaîne à tableau sans exploser
- 27. comment affecter des valeurs au tableau
- 28. Accéder au tableau dans MASM
- 29. html table au tableau ruby
- 30. Accès au tableau de NSMutableArray
Vous avez besoin d'une balise 'homework'? –