05-15-2023 03:05 PM
I have a cluster of 32-bit fixed-point values (FXP18.14) that I am converting to a byte array via typecast to string then string to byte array. LabVIEW uses 64-bits to store FXP values, so in this case half the bits are unused. When converting from a cluster like this, the ordering of the bytes for each FXP value gets swapped - the first 4 bytes are the unused values while the final 4 bytes are the actual FXP value. However, if I do this typecast on a single FXP value (not in a cluster) the byte ordering is as expected where the first 4 bytes holds the actual FXP value.
See attached test VI demonstrating this behavior, as well as screenshots below. I'm using LabVIEW 2019 SP1.
Is this a bug, or expected behavior? Does anyone know why the byte ordering is different when typecasting clusters vs single values? This only occurs with the FXP datatype as far as I can tell.
05-15-2023 05:00 PM
Your fixed point numbers are not what you think they are:
Not sure why LabVIEW is typecasting to 64 bits; tried with other FXP configurations.
05-15-2023 05:27 PM
@mcduff, LabVIEW uses 64-bits to store FXP numbers:
https://www.ni.com/docs/en-US/bundle/labview/page/lvhowto/numeric_data_types_table.html
Not sure what you mean by "your fixed-point numbers are not what you think they are"?
05-16-2023 03:37 AM - edited 05-16-2023 03:45 AM
@cjs7 wrote:Not sure what you mean by "your fixed-point numbers are not what you think they are"?
This may be because of your non-standard notation for fixed-points. Usually when we say "FXP 18,14" it means 18 bits in total of which 14 are in the integer part. So the sentence "I have a cluster of 32-bit fixed-point values (FXP18.14)" is a bit confusing. Actually your alternate notation could be more practical arithmetically if we are worried about precision, but less if we are thinking in terms of size taken by the data.
Anyway, I don't know why exactly the "Type Cast" function is behaving like this with FXP, but you can use "Flatten to String" and "Unflatten from String" instead. This way, the additional zeros are always put before the actual data:
05-16-2023 09:51 AM
@raphschru, thanks for pointing out the confusing notation.
Seems like flatten to string has more consistent behavior, so I'll switch to using that.