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.

 

Link to comment
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

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.