Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Convert String to hexadecimal using X++

(0) ShareShare
ReportReport
Posted on by 129
Dear experts,
 
Could you please help me to convert - String to hexadecimal using X++
 
Many thanks in advance.
 
Regards
Komal.
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,853 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.
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,853 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
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,996 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,853 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans