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

Announcements

No record found.

News and Announcements icon
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 139
Dear experts,
 
Could you please help me to convert - String to hexadecimal using X++
 
Many thanks in advance.
 
Regards
Komal.
  • Verified answer
    GirishS Profile Picture
    27,843 Moderator on at
    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
    240,742 Most Valuable Professional on at
    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
    240,742 Most Valuable Professional on at
    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 415 Most Valuable Professional

#2
CU10121822-0 Profile Picture

CU10121822-0 374

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 365 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans