Sign in to follow this  
SteveMyres

Syntax for direct one-step casting

Recommended Posts

It would be cool (my apologies if this already exists) to have compact syntax to directly extract a smaller size value from a variable/channel value without having to do an inline To.Bit() or whatever, and also to aggregate multiple consecutive values in an array as a larger type.

For example, if MyVariable is 64-bit, MyVariable:UW0 might return the most/least significant 16 bits, interpreted as an unsigned word.   MyVariable:37 might be the 37th least significant bit, and so on.   As a delimiter, I'd suggest a period or a colon if available.

If you had an array of smaller values, even if stored in 64-bit registers, you might be able to cast two consecutive ones into a single 64-bit value, interpreting each of the individual registers as 32-bit.  This is probably less useful than the other application, in a DAQ Factory context, where all numbers are automatically stored as 64-bit.

 

Share this post


Link to post
Share on other sites

First problem is that DAQFactory won't support a 64 integer in general.  All numbers in DAQFactory are stored as 64 bit floating point values (double precision floating point) which basically gives you 52-53 bits of integer.  The rest is exponent.  So, really to read 64 bit integers you need to split it into two 32 bit values and process them that way.

Moving on, you can pretty much do what you are asking with relatively simple bitwise math.  For example, to get just the least significant 16 bits of all values in an array, it is just:

array & 0xff

To get just bit 37 (numbered from 0):

array >> 37 & 0x01

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this