Page 1 of 1

interleaving algorythm

Posted: Fri Nov 18, 2011 1:32 pm
by CrypticalCode0
I needed this piece of code in a program i made for work it's really simple, the address is taken from dip switches.

Code: Select all

int8 address;
int8 inverse;
int8 upper_address;
int8 lower_address;

void interleave(void)
{
  inverse=address^0xff;
  for(int i=0;i<=8;i++){
    upper_address|=(address & 1 << i) << i | (inverse & << i) << (i + 1);
    lower_address|=(address & 1 << (i + 4) << i | (inverse & 1 << (i + 4)) << (i + 1);
}
This is not the exact code and this is used in a balanced bus system hence the inverse tagging along.

Before this i had a more cumbersome code full of magic numbers.
Anyhow i was wondering can anyone write a better version?

Re: interleaving algorythm

Posted: Fri Nov 18, 2011 2:56 pm
by gerryg400
What is it supposed to do ?

Re: interleaving algorythm

Posted: Fri Nov 18, 2011 3:04 pm
by AJ
Hi,

Your code wouldn't even compile. You're missing at least a '1' and a '}' and possibly more besides. As gerryg400 says, the first question is "What is it supposed to do?". The next word that springs to mind is "homework".

Even if we knew what the intended inputs and outputs were:
This is not the exact code
can anyone write a better version?
How are we expected to help in this situation?

Locked.