interleaving algorythm

Programming, for all ages and all languages.
Locked
CrypticalCode0
Member
Member
Posts: 81
Joined: Wed Nov 09, 2011 2:21 am
Location: Behind a keyboard located in The Netherlands

interleaving algorythm

Post 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?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: interleaving algorythm

Post by gerryg400 »

What is it supposed to do ?
If a trainstation is where trains stop, what is a workstation ?
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: interleaving algorythm

Post 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.
Locked