hi
i would like to know how to 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
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
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
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
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
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?
@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.
Ursula Kramarczyk (f. Piela)
zenon Support & Services | zenon Video Tutorials | zenon Trainings | local zenon contact