08-27-2008 07:19 PM
Hi,
I have 16 bit numbers (b0 to b15) that 4 of the bits mean nothing to me and need to be removed
More specifically, b1,b2,b8 and b9 have to be removed while, b0,b3,b4,b5,b6,b7,b10,b11,b12,b13,b14 and b15 need to be remained and put together into a 12bit sequence.
After that i need to invert b12, b13, b14 and b15.
Is there any way to work directly with this bits and do it fast as well?
an example number is
1001110100101010
which has to be converted to
1x x11110xx100101
111110100101
08-27-2008 08:36 PM
To invert bits, you can XOR the number with another number where the Bits you want to invert are 1, and the ones you don't are zero.
I believe the best way to eliminate the extra bits would be to convert the number to a boolean array and manipulate that.
One thing about your example. Remember that bit 0 is the least significant bit and would show up as the right most bit in a binary number. Bit 15 is the most significant bit and would the the one showing up to the left.
08-27-2008 09:23 PM
Thanks for the help, u are example though is for one number. What do i do for the case of an array.
Is there anyway to avoid conversion of each number individually in a loop?
I am attaching a vi with the data.txt required file.
Let me know if you have a quick and fast solution to this
Thanks,
CK
08-27-2008 09:45 PM - edited 08-27-2008 09:47 PM
Wrap the conversion code in a for loop with autoindexing tunnels going in and out.
There may be several other ways to do this, and perhaps some might not even need a loop. But I don't think you'll have any performance problems doing this in a loop or any special reason why a loop should be avoided.
See attached.
Watch out for how you do your bit manipulations. You are doing the inversion on bits 0 through 3, while your description said 12 through 15. You are either doing the opposite of what you said, or wrote up the descipription wrong for which bits you want to manipulate.