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

1. User
Join Date
28.11.2017
Posts
17

## 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. Employee
Join Date
08.12.2015
Posts
39

## 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. User
Join Date
28.11.2017
Posts
17

## 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. Employee
Join Date
08.12.2015
Posts
39

## 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. User
Join Date
28.11.2017
Posts
17

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

Originally Posted by anthony.burille
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. User
Join Date
28.11.2017
Posts
17

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

Originally Posted by mos89

thanks that is what i want to do !

Hi have an issue with negative number

#### Posting Rules

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