‎11-25-2011 06:04 AM
How would like to know how LabVIEW manages type conversion and type cast to fixed point.
In particular I have got two problems:
1) Suppose that I want to convert a signed 32-bit integer to a fixed point <+/-,20,20> with the "To-fixed-point" function.
Of course this conversion implies a loss of bits. Will LabVIEW keep the most significant bits or the least significant ones?
The same problem occurs if I want to convert a fixed point data (e.g. <+/-,20,20>) to another fixed point data with less bits (e.g. <+/-,10,10>).
2) I have a data represented with a fixed point <+/-,20,10> and I want to cast it to a fixed point <+/-,15,5> by removing 5 integer bits and keeping the sign.
For example I have the number -1.5 represented in <+/-,20,10> and I want to cast it to <+/-,15,5> (note that both representations can express the number correctly).
How can I perform such casting operation?
Thank you
Solved! Go to Solution.
‎11-25-2011 07:44 AM
‎11-28-2011 03:55 AM
Thank GerdW for answering.
Indeed, I tried some (all?) functions available to perform a cast between integers and fixed-point (FP) numbers.
This would not have been necessary if the LabVIEW documentation was a little more clear on the topic.
Anyway, I resume my results just in case anyone is interested.
In the following I assume that no overflow occurs. Moreover, all conversions are lossy: i.e. the final type has less bit than the initial one.
Integer -> FP:
FUNCTION EFFECT EXAMPLE -2 (=11111110b) int8 TO <+/-,6,4>
To Fixed-Point Preserve point position 1110.00b
Type Cast Preserve MSB 1111.11b
Integer To Fixed-Point Cast Preserve LSB 1111.10b
FP -> FP
FUNCTION EFFECT EXAMPLE 0000.1101b <+/-,8,4> TO <+/-,6,3>
To Fixed-Point Preserve point position 000.110b
Type Cast Preserve MSB 000.011b
FP -> Integer:
FUNCTION EFFECT EXAMPLE 00001.11010b <+/-,10,5> TO int8
To Integer Round to nearest integer 00000010b
Type Cast ??? 00001110b
Integer To Fixed-Point Cast Preserve LSB 00111010b
Please tell me if I missed or misunderstood anything.
‎11-28-2011 09:40 AM
Hi Tom,
What version of LabVIEW are you using? We put some effort into improving the accuracy of the documentation on the FXP-Integer Cast functions in 2010, so if you are in that version or later, I'd be interested in specific recommendations on what is deficient. For example, are the individual function topics unclear, or is it more that you can't find an overview of all the behaviors?
Thanks,
Jim
‎11-29-2011 03:42 AM
I am using LabVIEW 2010.
Currently I am using the FPGA module and the Control Design and Simulation Toolkit.
I know that writing good documentation is hard and I appreciate your efforts.
Nevertheless, I cannot find a detailed description of type cast effects, which is quite important if you are dealing with an FPGA.
‎11-29-2011 10:54 AM
Hi Tom,
That's a fair criticism, there's probably some tribal knowledge implicit in the documentation. I'll provide a few background notes that might help a bit:
‎11-30-2011 03:59 AM
Thank you for your explanation.
As a suggestion, I recommend to add some examples to LabVIEW Help, just like I tried to do in my previous post (actually it can be done better than I did).