C
Carramba
Hi!
I have two integers and I want exchnge they bits from certain position
(Crossover) as follows:
int main()
unsigned int crossPos;
unsigned int b, b1;
unsigned int value1, value2;
unsigned int result1, result2;
b = value2<<(31-crossPos);
b = b >>(31-crossPos);
result1 = value1 | b;
b1 = value1<<(31-crossPos);
b1 = b1>>(31-crossPos);
result2 = value2 | b1;
return 0;
}
but code seems uggly and feels unsafe.. what way would you recommend for
exchanges bit from certain position and down?
[31a 30a ...5a 4a 3a 2a 1a 0a] and [31b 30b ...5b 4b 3b 2b 1b 0b] from
position 3 =>
result1 = [31a 30a ...5a 4a 3a 2b 1b 0b]
result2 = [31b 30b ...5b 4b 3b 2a 1a 0a]
Thanx in advance
Carra
I have two integers and I want exchnge they bits from certain position
(Crossover) as follows:
int main()
unsigned int crossPos;
unsigned int b, b1;
unsigned int value1, value2;
unsigned int result1, result2;
b = value2<<(31-crossPos);
b = b >>(31-crossPos);
result1 = value1 | b;
b1 = value1<<(31-crossPos);
b1 = b1>>(31-crossPos);
result2 = value2 | b1;
return 0;
}
but code seems uggly and feels unsafe.. what way would you recommend for
exchanges bit from certain position and down?
[31a 30a ...5a 4a 3a 2a 1a 0a] and [31b 30b ...5b 4b 3b 2b 1b 0b] from
position 3 =>
result1 = [31a 30a ...5a 4a 3a 2b 1b 0b]
result2 = [31b 30b ...5b 4b 3b 2a 1a 0a]
Thanx in advance
Carra