web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Convert String to hexadecimal using X++

(0) ShareShare
ReportReport
Posted on by 133
Dear experts,
 
Could you please help me to convert - String to hexadecimal using X++
 
Many thanks in advance.
 
Regards
Komal.
I have the same question (0)
  • Verified answer
    GirishS Profile Picture
    27,827 Moderator on at
    Convert String to hexadecimal using X++
    Hi Komal,
     
    You can convert the string to int using Str2Int function and then pass it it int2hex to get the conversion.
     
    Thanks,
    Girish S.
  • Verified answer
    Martin Dráb Profile Picture
    237,679 Most Valuable Professional on at
    Convert String to hexadecimal using X++
    I'm assuming that you just want the bytes representing the text and then you want to save hexadecimal representation as text.
     
    But you have to realize that the number of bytes and their values depends on the text encoding you use, which you didn't specify. Here is an example with UTF-8:
    System.Text.Encoding encoding = System.Text.Encoding::get_UTF8();  
    System.Byte[] bytes = encoding.GetBytes(inputString);
    str hexString = System.Convert::ToHexString(bytes);
    Note that I wrote the code here, without any validation by compiler. Sorry if there are some mistakes.

    str2Int() would work only if the string consisted only of numeric characters and if we didn't care about encoding.
  • Verified answer
    Martin Dráb Profile Picture
    237,679 Most Valuable Professional on at
    Convert String to hexadecimal using X++
    Did it answer your question? I see you've created a new thread where you're using Encoding::GetBytes(), but you've never responded to use in this thread.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 563 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans