Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Is it possible to convert a string of 32-bit of binary to a float32?

marcosote
2023-03-23
2023-03-23
  • marcosote - 2023-03-23

    Hello everybody,

    I would like to know if it is possible to convert a string of 32-bit with binary data into a float32 data number.
    Example of inputs to the function:

    Input=00111110001000000000000000000000
    Output=0.15625

    The function should follow the rules given in the attached image to convert the string of booleans into a float number:

    The reason of this function is because I would like to read from bus REAL data type information. However, between the communication layer and my application software layer, there is another layer developed by someone (which I can't modify) that can only perform implementations type INT and BOOL, meaning that when somebody defines a a REAL data in the communication bus this layer only takes the integer part and sends this info to my application SW layer, loosing all the info related to the floating point.

    Example In/Out of what I have know

    Bus input = 100.12
    Intermediate layer = 100, this info is sent to my SW application layer
    Variable in SW application layer = 100.

    If it is possible to implement such function. I would like to know how to do it.

    Thanks everybody.

     

    Last edit: marcosote 2023-03-23
  • kislov - 2023-03-23

    Lazy solution using CAA Memory library.

     

    Last edit: kislov 2023-03-23

Log in to post a comment.