Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Convert Text to Hex

Posted on by 35

Hello

I want to convert text to hex using AL code. Is there any function that can do so?

I am working on cloud Business Central so I can't use any Dot Net library.

example:

Text Input = Bobs Records

Hex Result = 426F6273205265636F726473

Thanks

  • howeidat Profile Picture
    howeidat 35 on at
    RE: Convert Text to Hex

    it works. thank you

  • Suggested answer
    MahGah Profile Picture
    MahGah 15,428 on at
    RE: Convert Text to Hex

    Hi

    See this post  forum.mibuso.com/.../how-to-convert-text-to-hexadecimal-in-nav-2005

    specially the following by Duikmeester

    OnRun()
    MESSAGE('0x%1',ConvertBase16('Hogan'));
    
    LOCAL ConvertBase16(theInput : Text[512]) theOutput : Text[1024]
    FOR aIndex := 1 TO STRLEN(theInput) DO BEGIN
      aInt := theInput[aIndex];
      aLeft := ROUND(aInt / 16,1,'<');
      aRight := aInt MOD 16;
      theOutput += HexValue(aLeft) + HexValue(aRight);
    END;
    
    LOCAL HexValue(theValue : Integer) : Text[1]
    CASE theValue OF
      0..9: EXIT(FORMAT(theValue));
      10:   EXIT('A');
      11:   EXIT('B');
      12:   EXIT('C');
      13:   EXIT('D');
      14:   EXIT('E');
      15:   EXIT('F');
    END;

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans