LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

16bit binary to 12bit binary

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

 

 

0 Kudos
Message 1 of 4
(2,847 Views)

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.

Message 2 of 4
(2,839 Views)

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

 

 

Download All
0 Kudos
Message 3 of 4
(2,833 Views)

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.

Message Edited by Ravens Fan on 08-27-2008 10:47 PM
Message 4 of 4
(2,825 Views)