Re: significations des opérateurs \ et *
[ Nouvelle discussion
| Répondre au groupe
|
fr.comp.lang.basic ]
Sujet: Re: significations des opérateurs \ et *
De: NO_SPAM_jean_marc...@yahoo.fr.invalid (Jean-marc)
Groupes: fr.comp.lang.basic
Organisation: -= Belgacom Usenet Service =-
Date: 14. Mar 2008, 20:19:13
References: 1
|
val wrote:
> Bonjour,
>
> Je transcris un programme vb en c mais je ne sais pas comment
> interpréter les opérateurs
> \ (anti slash) et * (étoile) dans le code suivant d'un calcul de CRC.
>
>
> tCRC = 0
> For x = 1 To Len(sData)
> tIndex = ((tCRC \ &H100&) And &HFF&) Xor Asc(Mid(sData, x, 1))
> tCRCa = ((tCRC And &HFF&) * &H100&)
> tCRCb = tTable(tIndex) And &HFFFF&
> tCRC = (tCRCa Xor tCRCb) And &HFFFF&
> Next
> CRC16 = tCRC And &HFFFF&
Du coup la traduction devient triviale :
// Il suffit de mettre les bonnes constantes dans tTable ...
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
long tTable[256] = { 0x00, 0x01, 0x02, 0x04,
0x05, 0x06, 0x07, 0x08
/* define constants here */
};
long CRC16(unsigned char *sData)
{
long tCRC = 0L;
long tIndex = 0L;
long tCRCa = 0L;
long tCRCb = 0L;
long size = 0L;
long i = 0L;
size = strlen(sData);
for(i = 0L; i<size; i++)
{
tIndex = ((tCRC >> 8) & 0xFF) ^ sData[i];
tCRCa = (tCRC & 0xFF) << 8;
tCRCb = tTable[tIndex] & 0xFFFF;
tCRC = (tCRCa ^ tCRCb) & 0xFFFF;
}
return tCRC & 0xFFFF;
}
int main(void)
{
unsigned char testString[] = "COUCOU LES GARS";
long crc = 0L;
crc = CRC16(testString);
printf("crc = %ld\n", crc);
return 0;
}
--
Jean-marc Noury (jean_marc_n2)
Microsoft MVP - Visual Basic
FAQ VB: http://faq.vb.free.fr/
mailto: remove '_no_spam_' ; _no_spam_jean_marc_n2@yahoo.fr

|
 cette fonctionnalité est reservée aux membres ayant une session active !
|