Re: LFSR in c
- From: "Arthur J. O'Dwyer" <ajonospam@xxxxxxxxxxxxxx>
- Date: Wed, 27 Sep 2006 01:42:23 -0400 (EDT)
On Wed, 26 Sep 2006 dis_is_eagle@xxxxxxxxx wrote:
Hi.Thanks for the links. But can you explain it with a simple C
program?
(Explain the workings of a linear feedback shift register, you mean.
If you would say what you mean /in your post/, then we wouldn't have
to look backwards up the thread to find out what you're talking about,
and you might get more help. Certainly you'd be less annoying. Hint
hint.)
For example (this implements the same LFSR shown on the Wikipedia
article on LFSRs):
[UNTESTED CODE]
#include <stdio.h>
int LFSR(unsigned short *state, int (*f)(unsigned short))
{
int input = f(*state)? 1: 0;
int output = (*state & 0x8000)? 1: 0;
*state = (*state << 1) | input;
return output;
}
static int xorf(unsigned short val)
{
return ((val>>2) ^ (val>>3) ^ (val>>5)) & 1;
}
int main(void)
{
unsigned short state = 0x68F3;
printf("Output is %d\n", LFSR(&state, xorf));
printf("Output is %d\n", LFSR(&state, xorf));
printf("Output is %d\n", LFSR(&state, xorf));
printf("Output is %d\n", LFSR(&state, xorf));
printf("Output is %d\n", LFSR(&state, xorf));
return 0;
}
HTH,
-Arthur
.
- References:
- LFSR in c
- From: dis_is_eagle
- Re: LFSR in c
- From: CBFalconer
- Re: LFSR in c
- From: dis_is_eagle
- LFSR in c
- Prev by Date: Re: Filling a 2x2 array with random numbers such that...
- Next by Date: Re: regarding "perils of java schools"
- Previous by thread: Re: LFSR in c
- Next by thread: Einstein's Riddle in various programming languages?
- Index(es):
Relevant Pages
|