labview - Split Number into high and low words in C -


I want to send data from Labavi FPGA to a function using CV API. To synchronize the data transmitter, I do the following:

1) Input:

  • 3x I16 value
  • 1x U16 value
  • < / Ul>

    2) In two steps I pack these 4 values ​​in a U64 using the number function to add to the libewiew (this is hi.lo). So it's basically:

      ((I16.I16). (I16.U16)) (U32.U32) U64  

    3) Now This U64 value is moved to the C function, where it should be unpacked like this:

      U64 (U32.U32) ((I16.I16). (I16.U16) )  

    Now I wonder how unpacking will be handled in C. Is there something like "Split Number" function in LabView? How do I ensure that all the parts were assigned the correct data type?

No, no. You usually do this kind of thing that using bitview operations, mainly using shifts and masks:

const uint64_t incoming = 0xfeedcafebabef00d; Const int16_t first = (int16_t) (incoming & gt; 48); Const int16_t second = (int16_t) ((Inbound> 32) & amp; 0xffff; Const int16_t third = (int16_t) ((Inbound> 16) & amp; 0xffff); Const uint16_t fourth = incoming & amp; 0xffff;

It absolutely assumes that the endurance is appropriate everywhere, and first to 0xfeed (in decimal -275) and so on Will set.

As a general observation, the amount of actual code required for each extraction is low, which can tell why there is no general purpose to do this: you do not need one.

You can definitely write, if you like it:

  uint16_t extractU16 (uint64_t bits, uint8_t lsbIndex) {return (uint16_t) ((bits & Gt; & gt; LSBIndex and 0xffff); }  

Given this, you can rewrite the above version:

  const int16_t first = (int16_t) extractU16 (incoming, 48) ; Const int16_t second = (int16_t) extractU16 (incoming, 32); Const int16_t third = (int16_t) extractU16 (incoming, 16); Const uint16_t fourth = extractU16 (incoming, 0);  

We can do further (?) By doing a extractS16 () which gives int16_t to leave artists , But I will not be bothered. :)


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -