01-27-2011 06:14 PM - edited 01-27-2011 06:15 PM
I need to convert a Single Precision Floating Decimal number to 32-bit hexadecimal form, swap the high and low bytes, and convert that to a hex string. I have tried using the "Swap Word" function but it doesn't seem to have any affect on the Single number.
So
Input a Single Decimal # : 100
Convert to 32 bit Hexadecimal String with the low byte first: 0000 42C8
Any one have any ideas?
Thanks
Solved! Go to Solution.
01-27-2011 06:16 PM - edited 01-27-2011 06:19 PM
Use "flatten to string" and set the byte order to little endian.
01-27-2011 06:22 PM
awesome! thanks
01-27-2011 06:27 PM - edited 01-27-2011 06:29 PM
Actually, the above answer is incorrect if you really want the 100 -> 0000 42C8 functionality. You seem to want an unusual conversion.
Try this instead:
(left to right: typecast to U16 array, reverse array, typecast to string)
01-27-2011 06:27 PM
Sorry spoke too soon...
That using flatten string with little endian gives me "0000 C842" instead of "0000 42C8"
01-27-2011 06:34 PM
Yeah that's what i'm looking for. I am using Modbus RTU to control a motor controller and it calls for its data in that format.
01-27-2011 06:38 PM - edited 01-27-2011 06:39 PM
Slighly more lightweight, try casting to U32 and swap the words. Same difference. 😉
(apparently, swap words is a NOOP for SGL, but still accepts SGL without coercion dot. Interesting...)
01-27-2011 07:10 PM
01-27-2011 09:08 PM
@altenbach wrote:
(apparently, swap words is a NOOP for SGL, but still accepts SGL without coercion dot. Interesting...)
I have the feeling that the current behavior of swap words is incorrect for SGL inputs. I created an note in the monthly bug thread. Any comments are welcome.
01-27-2011 10:29 PM - edited 01-27-2011 10:31 PM
@altenbach wrote:
@altenbach wrote:
(apparently, swap words is a NOOP for SGL, but still accepts SGL without coercion dot. Interesting...)
I have the feeling that the current behavior of swap words is incorrect for SGL inputs. I created an note in the monthly bug thread. Any comments are welcome.
My guess is that this is somewhat intended behavior. You are able to wire a cluster with multiple data types and it will swap bytes/words on integers and leave the others alone. Not that I have ever thought about doing this....
still seems a bit strange.
Detailed Help: data is an integer, an array of integers, or a cluster containing integers that you want to byte swap. If data is a cluster that contains integers, this function swaps only the integer elements of the cluster.