LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

swap binary data endianess

Hello all, I have a preconfigured FPGA, which is outputting 8bit unsigned binary data in packets (which are 90bytes long). I'm reading this data into LabView using VISA (over RS232). The VISA-Read is converting the binary to hex (as I expect), but it's doing it with the wrong endianess, so the hex is meaningless (i.e. I get a 2 when I expect 64 etc). I can see may ways (both through inbuilt functions and solutions suggested here) for correcting endianess of multiple bytes ("Swap Bytes" for example), but none for changing this internal to a single byte, nor can I see a means of configuring VISA in this respect. Am I missing something obvious? All suggestions welcome, thank you!
0 Kudos
Message 1 of 6
(3,573 Views)

Endian.png

 

Something like this?


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 6
(3,570 Views)

Jeff,

 

It looks like your code swaps nibbles within a byte.  I'm not sure there is such a thing as nibble endianess.

 

I think edf is looking not at endianess, but reversing the order of  bits.  least significant bit vs. most significant bit first.

 

Try converting the U8 to boolean array, reverse the 1-D boolean array, then convert back to a U8.

0 Kudos
Message 3 of 6
(3,533 Views)

I think Ravens Fan is right about the bit reversal, two ways I do it:

 

BitReversal.png

 

Of course, by lame I mean simple and fast.

Message 4 of 6
(3,524 Views)

I never heard of a format with reversed bits. Are you sure that's what it actually is?

Can you attach a VI containing a typical 90byte raw data set and the desired result?

 

I would go with the Lookup table as in Darin's top example. If you disable debugging, it will get folded into a constant at compile time and is thus extremely efficient at runtime. (or just make it into a constant manually as Darin did).

 

 

(Darin, that second algorithm is weird. These guys have way too much time on their hand: Inflate each byte 8x to U64 just to do some obscure binary operations then shrink it back later... 🐵

0 Kudos
Message 5 of 6
(3,507 Views)

Darin, altenbach, thank you!

 

We're pretty sure the data is bit-reversed. The FPGA deivce outputting the data is custom, and so could easilly be outputting reversed bits if thats what the guy who built it felt like doing. There are a number of fixed marker bytes in the packet (as well as start and stop bytes), and the only way these are what we expect them to be is by reversing the bits. Then the whole packet looks more sensible. Wierd I know, and most confusing, as it took us a week to figure out why it wasn't working the way we expected!

0 Kudos
Message 6 of 6
(3,477 Views)