Convertion Dint to Word

pascaljt
2023-08-07
2023-08-07
  • pascaljt - 2023-08-07

    Hello,
    I would like to convert a DINT format in Word but with a different way to TO_WORD.
    For example, if I use TO_WORD with 70 000 ( 1 1170 hexa) I will have only a word with the value 1170 (hexa). I would like to convert the value 70 000 (decimal) with a LSB word and MSB word.

    How can do that ?

    Thanks for your help.
    Pascal.

     
  • ph0010421 - 2023-08-07

    Hello
    With a UNION:

    TYPE uDINT_WORD :
    UNION
        AsDINT: DINT;
        AsWORDs: ARRAY[0..1] OF WORD;
    END_UNION
    END_TYPE
    

    then create a variable of this type and the WORDs

    MyDINT: uDINT_WORD;
    LSW: WORD;
    MSW: WORD;
    

    Then you can access the WORDs...

    MyDINT.AsDINT := 70000;
    LSW := MyDINT.AsWORDs[0];
    MSW := MyDINT.AsWORDs[1];
    
     

    Related

    Talk.ru: 1

  • pascaljt - 2023-08-07

    Hello ph0010421,

    Many thanks for your answer, it's perfect :)

     
    πŸ‘
    1

Log in to post a comment.