Programming, for all ages and all languages.
CrypticalCode0
Member
Posts: 81 Joined: Wed Nov 09, 2011 2:21 am
Location: Behind a keyboard located in The Netherlands
Post
by CrypticalCode0 » 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.
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
Posts: 1801 Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia
Post
by gerryg400 » Fri Nov 18, 2011 2:56 pm
What is it supposed to do ?
If a trainstation is where trains stop, what is a workstation ?
AJ
Member
Posts: 2646 Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:
Post
by AJ » Fri Nov 18, 2011 3:04 pm
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.