J
Julia Donawald
Hi,
I have the following problem, and till now sadly I couldnt find an
algorithm which does the job well. My problem is as follows:
Given for example the following bit-value ( saved as unsigned long ):
001101000001101010, so the unsigned long variable has the value:
53354. Furthermore I know the length of this bit-value ( here: 18 ).
Now I want to delete the leading 8 bits of such a bit value, so that
after the operation I get the value: 0001101010.
At the moment I solve this problem as follows, but I am not satisfied
with this solution:
unsigned long helper = (output << (16-output_len)) & 0xFFFF;
unsigned long output = helper >> (16-output_len);
The problem is now that if for example I only have an output-len > 16
then this algorithm wont work. I know I could solve this with a simple
if-else-block, but then I have again the problem what would happen if
the output len is <= 24 and so on. So I am searching for a more
general algorithm on that problem.
Thanks in advance for any help.
Bye,
Julia
I have the following problem, and till now sadly I couldnt find an
algorithm which does the job well. My problem is as follows:
Given for example the following bit-value ( saved as unsigned long ):
001101000001101010, so the unsigned long variable has the value:
53354. Furthermore I know the length of this bit-value ( here: 18 ).
Now I want to delete the leading 8 bits of such a bit value, so that
after the operation I get the value: 0001101010.
At the moment I solve this problem as follows, but I am not satisfied
with this solution:
unsigned long helper = (output << (16-output_len)) & 0xFFFF;
unsigned long output = helper >> (16-output_len);
The problem is now that if for example I only have an output-len > 16
then this algorithm wont work. I know I could solve this with a simple
if-else-block, but then I have again the problem what would happen if
the output len is <= 24 and so on. So I am searching for a more
general algorithm on that problem.
Thanks in advance for any help.
Bye,
Julia