Configuring a 2's compliment

vvora
2021-11-29
2024-09-28
  • vvora - 2021-11-29

    Hi,

    I have an array of Bytes reading different messages from a COB-ID, one of them is a 16 bit signed INT, 2's compliment and other one is 16 bit unsigned INT, 2's compliment. What would be the best way to read them. Any function block for conversion? I assume I will have to take 2's compliment of the data read?

    Thanks

     
  • liamb - 2024-09-27

    Hi, did you end up finding a way to take 2's compliment?

     
  • TimvH

    TimvH - 2024-09-28

    You could create a DUT of the Type Union and add an array of 2 bytes + an Int.
    Then write the byte values in the array of the Union and read the Int.

    Or

    VAR
        iInt : INT;
        byHigh : BYTE := 2#1111_1111;
        byLow : BYTE := 2#1111_1111;
    END_VAR
    
    iInt := TO_INT(byHigh*16#100 + byLow);
    
     

Log in to post a comment.