Conversion d'un int en octets
Bonjour à tous, je voudrais effectuer une conversion d'une variable de type int en octets. Pour celaj'ai défini le type suivant :
Code:
typedef unsigned char byte;
Je définis ensuite la fonction suivante :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| byte * toBytes() {
byte * tab;
tab = (byte *) malloc (sizeof(2 * sizeof(int) + TAILLEBUF * sizeof(char)));
int val = _codeOperation;
int i;
for (i = 0; i < 4; i ++) {
tab[i] = (byte) (val & 000000FF);
val = val >> 8;
}
for (i = 0; i < TAILLEBUF; i ++) {
tab[i + 4] = _msg[i];
}
val = _valeur;
for (i = 0; i < 4; i ++) {
tab[i + 4 + TAILLEBUF] = (byte) (val & 000000FF);
val = val >> 8;
}
return tab;
} |
Problème à la compilation :
Code:
1 2 3 4
| spulvera@scinfe129 ~/Desktop/projet/C
$ gcc -c MessageConsole.c
MessageConsole.c:33:28: erreur: suffixe « FF » invalide pour une constante entière
MessageConsole.c:41:44: erreur: suffixe « FF » invalide pour une constante entière |
Est-ce que quelqu'un pourrait m'aider svp??
Merci d'avance.