Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 946629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:56:58+00:00 2026-05-15T22:56:58+00:00

I developed the following function to convert strings to hex values. function StrToHex(const S:

  • 0

I developed the following function to convert strings to hex values.

function StrToHex(const S: String): String;
const
  HexDigits: array[0..15] of Char = '0123456789ABCDEF';
var
  I: Integer;
  P1: PChar;
  P2: PChar;
  B: Byte;
begin

  SetLength(Result, Length(S) * 2);
  P1 := @S[1];
  P2 := @Result[1];

  for I := 1 to Length(S) do
  begin
    B := Byte(P1^);
    P2^ := HexDigits[B shr 4];
    Inc(P2);
    P2^ := HexDigits[B and $F];
    Inc(P1);
    Inc(P2);
  end; 

end; 

Now I was wondering whether there is a more efficient way to convert the strings?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:56:59+00:00Added an answer on May 15, 2026 at 10:56 pm

    Depending on your Delphi version:

    D5-D2007

    uses classes;
    function String2Hex(const Buffer: Ansistring): string;
    begin
      SetLength(result, 2*Length(Buffer));
      BinToHex(@Buffer[1], @result[1], Length(Buffer));
    end;
    

    D2009+

    uses classes;
    function String2Hex(const Buffer: Ansistring): string;
    begin
      SetLength(result, 2*Length(Buffer));
      BinToHex(@Buffer[1], PWideChar(@result[1]), Length(Buffer));
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed the following C code to mask data before sending back to
I developed an RSS feed following a tutorial and I think the .xml file
I developed a website for 1024x768 and used the following viewport: <meta name=viewport content=width=768,
In a JSF 2 application, which is developed on tomcat, I have the following
At the following URL: https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsICacheVisitor is the following code chunk: boolean visitDevice(in string deviceID,
Consider the following situation: I want to replace links in a string, specifically I
I'm a total javascript noobie. I developed the code bellow following and modifing some
The following C# code is used in a service I have inherited, to convert
I have developed a cumulative sum function as defined below in the Haskell library
I'm working on a site someone else developed. They used the following jQuery code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.