From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

extracting a particular bit from byte- a different view



@VivekM wrote:
i just wanted to tell alten that i m using labview 6.1 so the code he sent doesnot opens on my pc.... but i'll try the thingsu both told me...

LabVIEW 6.1 is pretty old, and the visual appearance of some of the icons has probably changed. For simplicty I'll tell you the names of the functions used. If you don't see them, use the search function of the palette:


Top-left: "array size" -- "quotient & remainder" -- "reshape array".

Bottom left: The "scale by power of two" acts identical to a "logical shift" for integer inputs (This wasn't always the case, so if you have a very old LabVIEW version you should substitute a "logical shift" operation). The diagram constant is an U8 integer with a value of "1".

Loop: the diagram constant is an U8 integer with a value of zero.

Inner loop: "AND" (boolean palette) -- "scale by power of two".

Case structure: default case:  "OR" (boolean palette). The other case is case "0" (zero) and contains only a single wire connection the upper two tunnels.

Just wire it up as shown, should only take minutes. Make sure there are no coercion dots, else some of the representations are wrong.

Good luck! 🙂

Message Edited by altenbach on 04-27-2007 10:10 AM

0 Kudos
Message 11 of 22
(1,810 Views)
One quick code cleanup: the "scale by power of two" inside the loop belongs inside the case structure, we don't need to shift unless we actaully need the result later. 😉
0 Kudos
Message 12 of 22
(1,796 Views)
hi alten....
thanx for ur help...
well i wanted to know , how u defined output array?
and one more problem is coming... how to map the file contents to the array ... In my code i have connected the file data from read file vi to the build array terminal.. now as it comes out to be a 1d array  the  the quotient and remainder terminal shows an error while connecting to the dimension size terminal of reshape array as the dimensions doesnot match...
and still i m not clear with how to read data from file into arrays and then process it and again make a file of it...
 
please help
 
vivek modgil 
0 Kudos
Message 13 of 22
(1,774 Views)
Sorry, what you are sayins is not very clear to me.
 
Could you just attach your code and an example data file.
0 Kudos
Message 14 of 22
(1,768 Views)


@VivekM wrote:
and still i m not clear with how to read data from file into arrays and then process it and again make a file of it...
 
please help
 
vivek modgil 


If your file is a txt file, use the Spread String to Array icon after the Read File icon, to get the data converted into U8 as Altenbach had mentioned earlier in Reply 7 on this post.

See the attached VI to get a rough idea of what you should do.

- Partha ( CLD until Oct 2024 🙂 )
Message 15 of 22
(1,755 Views)
For again to make this data into a file, you ve to convert it from Array to Spreadsheet String & write it to the file. Smiley Wink
- Partha ( CLD until Oct 2024 🙂 )
0 Kudos
Message 16 of 22
(1,756 Views)


@altenbach wrote:
 
Could you just attach your code and an example data file.

Vvek,

I forgot to emphasize what Altenbach had asked earlier.

What type of file are youhaving ? Is it a txt file ? Does it have one column [ or row ], or multi columns [ rows ] ?

You ve to clarify us regarding these questions first, so as to put things on the right track.

- Partha ( CLD until Oct 2024 🙂 )
0 Kudos
Message 17 of 22
(1,754 Views)
In general, for bit extraction from a byte, wouldn't the following be a straightforward solution?





Message Edited by DonRoth on 06-02-2008 10:15 AM
0 Kudos
Message 18 of 22
(1,549 Views)

DonRoth wrote:
In general, for bit extraction from a byte, wouldn't the following be a straightforward solution?

Don,
As a first step, you can delete the FOR loop. Boolean to 0,1 accepts array inputs. 😉
 
One thing we learned from the old bit twiddling challenge is to avoid green array wires. All you need is do a bitwise AND with "1" shifted by the desired amound and see if the result is zero. The code shown below will do the exact same thing.
Your code takes one byte, turns it onto a boolean array (8 bytes), then turns that into an I16 array with 8 elements (16 bytes), only to keep a I16 result. Basically, you are wasting at least 24 bytes of intermediary storage in the process of operating on the information content of a single byte. (it is actually much more, since you are also displaying the I16 array).
 
Yes, for small problems, it does not really matter which code you use, but once you need to process large amouts of data, the performance can be orders of magnitude different depending on the algorithm. 🙂 I always go for the lean solution. 🙂
 


Message Edited by altenbach on 06-02-2008 08:59 AM
0 Kudos
Message 19 of 22
(1,540 Views)
In my case, only one byte needs to be processed but I always prefer the optimized solution.  Thanks!
 
Don
0 Kudos
Message 20 of 22
(1,533 Views)