Page 1 of 2 1 2 LastLast
Showing results 1 to 10 of 13

Thread: how to convert the content of a variable in decimal into an hexadecimal value

  1. #1
    Join Date
    28.11.2017
    Posts
    17

    Default how to convert the content of a variable in decimal into an hexadecimal value

    hi 

    i would like to know how to to convert the content of a variable in decimal into an hexadecimal value

  2. #2
    Join Date
    08.12.2015
    Posts
    39

    Default Re: how to convert the content of a variable in decimal into an hexadecimal value

    Hello,

    The value of a variable is always the same, in decimal, binary, hexadecimal... But you can view the hexadecimal form of a value, in debug (so while you are online or in simulation) doing a right-click on it > Hexadecimal display.
    If you want to recover the hexadecimal value of a variable in a STRING you can use the "HTOA" block.

    I hope it helps,
    Anthony

  3. #3
    Join Date
    28.11.2017
    Posts
    17

    Default Re: how to convert the content of a variable in decimal into an hexadecimal value

    hi anthony

    i try to format a value from a DINT into an 8 bytes array

    1 bytearray[0]= 16#55 ascci code of 'U'
    2 bytearray[1]= 16#49 ascci code of 'I'
    3 bytearray[2] and  bytearray[3]= 16#01 index in hexa of my destination array

     bytearray[4]  bytearray[5] bytearray[6]  bytearray[7] value in hexa of my parameter

    so i am doing a serialize out to fill my value array but the user input the value in decimal i want to write it in the array in hexa

  4. #4
    Join Date
    08.12.2015
    Posts
    39

    Default Re: how to convert the content of a variable in decimal into an hexadecimal value

    Hi !

    Mmmh... You mean, for example, the user is writing "85" (decimal value of 16#55) but you do not want to write "85" in your array of BYTEs, you want to have "55" (because it's the hexadecimal value), right?

    Then I think you can use the HTOA block this way:

    MyHexValue_0 := HTOA(DecimalUserValue_0); // Converts the decimal value (85) in hexa and stores it in a STRING ('55')
    bytearray[0] := ANY_TO_USINT(MyHexValue_0); // Converts the STRING in an USINT (55) so you can store it in the array
    Last edited by anthony.burille : 29th May 2018 at 14:47

  5. #5
    Join Date
    28.11.2017
    Posts
    17

    Default Re: how to convert the content of a variable in decimal into an hexadecimal value

    Quote Originally Posted by anthony.burille View Post
    Hi !

    Mmmh... You mean, for example, the user is writing "85" (decimal value of 16#55) but you do not want to write "85" in your array of BYTEs, you want to have "55" (because it's the hexadecimal value), right?

    Then I think you can use the HTOA block this way:

       MyHexValue_0 := HTOA(DecimalUserValue_0);     // Converts the decimal value (85) in hexa and stores it in a STRING ('55')
       bytearray[0] := ANY_TO_USINT(MyHexValue_0); // Converts the STRING in an USINT (55) so you can stores it in the array


    thanks that is what i want to do !

  6. #6
    Join Date
    28.11.2017
    Posts
    17

    Default Re: how to convert the content of a variable in decimal into an hexadecimal value

    Quote Originally Posted by mos89 View Post





    thanks that is what i want to do !



    Hi have an issue with negative number
    Attached Thumbnails Attached Thumbnails Untitled.jpg  

  7. #7
    Join Date
    28.11.2017
    Posts
    17

    Default Re: how to convert the content of a variable in decimal into an hexadecimal value

    Quote Originally Posted by mos89 View Post






    Hi have an issue with negative number
    not only negative numbers:
    myVarinHex_0 is a tmp variable in DINT




    Attached Thumbnails Attached Thumbnails Untitled2.png  

  8. #8
    Join Date
    08.12.2015
    Posts
    39

    Default Re: how to convert the content of a variable in decimal into an hexadecimal value

    Hi,

    Aaaah... Yes, of course, I was focused on the '55' example, this was easy because converting a STRING to a DINT, it will not recognize this is an haxadecimal form, it processes the value by elimination, from the left to the right:

    STRING | DINT
    '55'       | 55
    '5 6'      | 5
    '5E'       | 5
    '16#5E' | 16

    So "strictly" converting a STRING which contains other characters than numbers, into a DINT, this is not possible.
    And of course hexadecimal values are often containing 'A', 'B', 'C', 'D', 'E' and 'F'...
    Then, this is not possible to do it using the SERIALIZEIN/SERIALIZEOUT functions because these are using array of bytes.

    But... Why storing hexadecimal values?
    As I said in the first post, if you store 85 in decimal, or 16#55 or 2#01010101, the value will be the same, it still is 85.
    If you strictly want to store the hexadecimal form of a value, then you have to store it in an array of STRING

  9. #9
    Join Date
    26.02.2021
    Posts
    24

    Default Re: how to convert the content of a variable in decimal into an hexadecimal value

    Is this what you would do if you have to translate the value of a dint to individual bits values? Is there a way to do it without Logic? just with the Zenon local functions/elements/variable configuration?

  10. #10
    Join Date
    01.07.2008
    Location
    Salzburg, AT
    Posts
    983

    Default Re: how to convert the content of a variable in decimal into an hexadecimal value

    @mst: please do not advise people to use a solution with simulator driver: it potentially results in licensing issues and it anyway not transfers the timestamp of variable value.  

Similar Threads

  1. Styles content is not visible in Zenon 7.60
    By rahulindore05 in forum zenon Service Engine Supervisor
    Replies: 2
    Last Post: 12th May 2018, 08:14
  2. Comma as separator for decimal value
    By altera in forum zenon Service Engine Supervisor
    Replies: 4
    Last Post: 23rd August 2016, 10:17
  3. Convert variable for Process Gateway
    By diemon in forum Drivers
    Replies: 5
    Last Post: 3rd March 2015, 09:07
  4. Dynamic limit texts with hexadecimal value
    By lew in forum zenon Service Engine Supervisor
    Replies: 1
    Last Post: 9th January 2012, 00:41
  5. convert anything to bit
    By brandt in forum Engineering Studio Logic & Logic Service (former zenon Logic Workbench & Runtime)
    Replies: 0
    Last Post: 7th February 2008, 13:04

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •