interleaving algorythm
Posted: Fri Nov 18, 2011 1:32 pm
I needed this piece of code in a program i made for work it's really simple, the address is taken from dip switches.
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?
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);
}
Before this i had a more cumbersome code full of magic numbers.
Anyhow i was wondering can anyone write a better version?