04-16-2009 07:13 PM
I am creating an app that will recieve a string of true binary data (not ascii binary) and want to extract a certain number of bits( 1 bit, 27 bits, 11 bits, etc.) from it at any location at a given time. Any suggestions. I can't send my code due to the job restrictions.
Josh
04-16-2009 07:22 PM
Typically you will BITWISE AND a binary number with a binary number where the number has all zeros except the test bit then see if the number is greater than zero, if yes the the bit was set.
ie for a 16 bit number, to test the 11th bit you would and the original number with 0000010000000000 (this is the decimal number 2^11 or 2048). In labview you also can use the number to boolean array and index the array by the bit index and see if it is true or false.
04-16-2009 07:31 PM - 編集済み 04-16-2009 07:38 PM
What do you mean by 'true binary data'? What LabVIEW data type is your input?
If you're extracting a number of bits from the middle of a large number and you do a bitwise AND to extract the part you want, you may also need to bit shift the data so to get the right result.
Eg. AND 010110010
With 000110000 will give you 48, but the answer you may want is 3 because you only want the value of a 2 bit number.
Perhaps you could give an example table of 'data in - data expected out', including LabVIEW data types.
Eg.
Data in(U8 array) BitOffset(U32) BitLength (U32) Result(U32)
0xBEEF 5 3 7
0xABBA 4 4 11
0xDEAD 13 2 2
04-16-2009 09:57 PM
04-16-2009 10:05 PM
How long is your bit stream? (How long is a peice of string?...What is the maximum you expect it to be?)
Is it an array of U8s? A sample of real[istic] data would be useful.
04-16-2009 10:07 PM
04-16-2009 10:21 PM
04-16-2009 10:24 PM
What data type do you want as your output? Integer? Array of U8s? Boolean Array?
I always try and avoid a lot of array manipulation, it tends to be slow. And storing data as a boolean array is inefficient too. I believe each bit is stored as a byte anyway.
With a U8 array as input, I would start by getting an array subset starting at 'BitOffset' modulo 8 (BitOffset%8) and array length of BitLength modulo 8 +1...or something like that.
This reduces the size of the array you're working with first.
What you do next depends on the data type you want out.
04-16-2009 10:25 PM
04-16-2009 10:27 PM