predator/bits_per.c

32 lines
569 B
C
Raw Permalink Normal View History

2021-10-27 21:58:56 +00:00
#include <stdio.h>
#include <math.h>
/* This program is made available under the terms of the GNU Copyleft */
int main(void)
{
char symbols[20];
double sym;
double bits;
/*get the nums*/
printf("How many symbols are available in this system ?\n");
//gets(symbols);
if (fgets(symbols,20,stdin) == NULL) { exit(1);}
/*conv to values*/
sym=atol(symbols);
bits= log10(sym) / (log10(2));
/*shannon's law is expressed in terms of log2(x) hence fiddly conversion*/
printf("This is a radix=%g system with %g bits per symbol.\n\n", sym,
bits);
return 0;
}