LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

extracting a particular bit from byte- a different view

hi
well in my last query,i think the question was wrongly interpreted.... i again explain it..
i have acquired data through pattern generation method and made a file of it... now what i want is that as the data is read from the port as  byte data , i want a particular bit from that 8 bit data  and then after taking that particular one bit each time from 8 bytes  ,combine those   8 bits to form a byte of data, and this process must be repeated till whole of the data in the file is read. 
please help
 
regards
 
vivek modgil
0 Kudos
Message 1 of 22
(4,003 Views)

traditional bit extraction id done with bitwise anding.  that is to see if the 3rd bit is set and the 8 bit number with 2^3 or 00000100.

if the result is =0 then the bit was 0 else the bit was 1.  do this for each bit and recombined them at the end.  you also can change a 8bit number to an array of booleans and deal with them that way, but that is less efficeint.

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 2 of 22
(3,987 Views)
You can do something like shown in the attached picture.
If you have your data in U8 representation you can use the binary functions AND (to extract a bit) and OR (to set a bit).
The attached code extracts bit 3 of all 8 bytes and, if this bit is 1, sets bit number i (loop counter) in the output byte.



Of course you'll need another loop to read the data in blocks of 8 bytes. If you read them as a string, use the "String to byte array" function to transform it into an array of U8.

Hope this helps,
Daniel

Hm, Paul was quicker 😉

Message Edited by dan_u on 04-26-2007 02:20 PM

Message 3 of 22
(3,988 Views)
Please try not to post NEW thready to clarify a previous thread.  In 6 months time, nobody will know which "previous thread" you are referring to.

You can clarify your questions in the original thread.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 4 of 22
(3,977 Views)
Here's a quick draft (LabVIEW 8.2.1).
 
Possible needed tweaks:
  1. If you want the bits in reverse order on the output, just use "7-[1]" instead of [i] in the inner loop.
  2. Code assumes that input array size is a multiple of 8 and truncates otherwise. If you want to pad to the next higher multiple, just adjust the reshape array part.
 
Makes sense?
 

Message Edited by altenbach on 04-26-2007 09:30 AM

Download All
Message 5 of 22
(3,965 Views)

Thank you all for ur help.

Dan  i was trying the same thing what u have sent me... the problem is at input.... i have to input the data directly from file i.e. i will mention the file path as the file already exists...from that file the code should  read data byte  by byte (to extract particular bit  from each byte in a group of 8 bytes) and then make another data byte and write it in new file.

 please help

regards

vivek modgil

0 Kudos
Message 6 of 22
(3,948 Views)
How big are the files?
 
It is usually not recommended to read and write files byte-by-byte. Disk I/O is slow and is is much more efficient to do the entire thing in memory.
 
Just read the entire input file as an array of U8 numbers, pipe it through my code above, the write the result back to a file.
0 Kudos
Message 7 of 22
(3,941 Views)
Well you can open the file, wire the file reference to a while loop and in the loop read 8 characters per iteration. The read file functions have a count input, just wire 8 to it. Convert the read string to an array of U8. If you reach EOF (end of file), terminate the loop and close the file. As altenbach said, you might need special treatment here if the last block is shorter than 8 bytes.

Daniel

Message Edited by dan_u on 04-27-2007 08:18 AM

0 Kudos
Message 8 of 22
(3,942 Views)
thanx.....
i will try this....
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...
lets see what the result comes out...
hope for the best...
thanx and regards
 
vivek modgil
0 Kudos
Message 9 of 22
(3,940 Views)

Vivek,

What is there, even if you dont have 8.21 ?

He has attached a screenshot for users like us only that dont have the latest version. Smiley Wink

Code it yourself similarly & update here for the results you get.

- Partha ( CLD until Oct 2024 🙂 )
0 Kudos
Message 10 of 22
(3,929 Views)