From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
07-11-2018 05:59 PM
Hello,
I was wondering if I could get some help on swapping bytes in LabVIEW? The data I'm reading in is a 3 byte integer in binary format with the most significant byte first, and I want to swap the LSB with the MSB. I'm thinking of extracting the bytes using the AND operators and swap the bytes, but that sounds inefficient . Is there a VI that's similar to swapping 2 bytes?
Thanks in advance.
07-11-2018 06:55 PM
LabVIEW does not have a 24-bit number, so when you get your data, you can convert it to a 32-bit number, and then to an array of Bytes which will have 4 elements. Get rid of the first Byte and you will have your 3-byte array. Then you can reverse the array order to swap the 2 bytes on the ends.
07-11-2018 08:23 PM
LabVIEW also has direct functions for doing byte and word swaps (as well as splits and joins). You can find them under the palette Numeric-->Data Manipulation.
Another thing that may be useful there is the pair of functions "Flatten to String" and "Unflatten from String". They can also be used to reverse byte order by setting endian-ness.
Below is a quick illustration of both:
-Kevin P
07-12-2018 02:23 AM
Of course you can use a rotate or shift (after the swaps or unflatten) to go from 80402000 to 00804020 if that's what you want.
07-12-2018 06:46 AM
@SegFault1119 wrote:
The data I'm reading in is a 3 byte integer in binary format with the most significant byte first
Could you be more specific about how you are storing this data? An example VI would help us help you.