1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
   | #include <malloc.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
int compute_log(int);
unsigned int prim_poly_4 = 023;
unsigned int prim_poly_8 = 0435;
unsigned int prim_poly_16 = 0210013;
 
unsigned short *gflog, *gfilog;
 
int main ()
{
	//if you use the function get_sentence
 
	int NW;
	int k;
	int i;
//	int temp[3]={8, 16, 256};
	FILE *pt;
	char *nom = "gflog8.h";
	char  *test;
 
	pt = fopen(nom,"wt"); 
    fputs ("int *gflog8={",pt);
 
	NW = 8;
 
	i = compute_log(NW);
	if (i == -1) printf("NW should be 4, 8 or 16\n");
 
 
	for(i=0;i<NW;i++)
	{
		test = (char *) gflog++;
 
		fputs(test,pt);
                fputs (", ",pt);
		test++;
	}
fputs ("}",pt);
return 1;
}
////////////////////////////////////////////////////////////::
int compute_log(int NW)
{
	unsigned int b, log, x_to_w, prim_poly;
	int w;
 
	w = (int) (log10 ( (double) NW) / log10(2));
 
	switch(w) {
	case 4:		prim_poly = prim_poly_4;	break;
	case 8:		prim_poly = prim_poly_8;	break;
	case 16:	prim_poly = prim_poly_16;	break;
	default:	return -1;
	}
 
	x_to_w = 1 << w;
	gflog = (unsigned short *) malloc (sizeof(unsigned short) * x_to_w);
	if(gflog == NULL) 
	{
	    fprintf(stderr,"Allocation gflog impossible \n");
	     exit(EXIT_FAILURE);
	}
	gfilog = (unsigned short *) malloc (sizeof(unsigned short) * x_to_w);
	if(gfilog == NULL)
	{
	    fprintf(stderr,"Allocation gfilog impossible \n");
	     exit(EXIT_FAILURE);
	}
	b = 1;
 
	for (log = 0; log < x_to_w-1; log++)
	{
		gflog[b] = (unsigned short) log;
		gfilog[log] = (unsigned short) b;
		b = b << 1;
		if (b & x_to_w) b = b ^ prim_poly;
	}
 
	return 0;
 
} | 
Partager