I need to merge two variables. They both are unsigned ints.
- First: 11000000
- Second: 11111010000
Desired output:
11011111010000
In words: I need to put all the 1 followed by one 0 (in first number) in front of the whole second number. The only think that come to my mind is, to bit shift the first number to the left as many as the length of the second is. And than sum it. But i don’t know the length. Though it probably could be found, isn’t there a better easier way?
Thx
bit shift the first to the right until you have a series of 1’s with no trailing 0.
then bit shift it to the left for the “length” of the second plus 1 (really the amount of bits after and including the first 1)
and then OR them together, don’t sum or else bugs could arise.