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

  • SEARCH
  • Home
  • 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 8755531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:52:34+00:00 2026-06-13T13:52:34+00:00

I have an array of byte that I wish to convert into a hex

  • 0

I have an array of byte that I wish to convert into a hex string, and then back into an array of byte.

I am using the following to convert into a hex string:

function bintoHex(const bin: array of byte): String;
const HexSymbols = '0123456789ABCDEF';
var i: integer;
begin
  SetLength(Result, 2*Length(bin));
  for i :=  0 to Length(bin)-1 do begin
    Result[1 + 2*i + 0] := HexSymbols[1 + bin[i] shr 4];
    Result[1 + 2*i + 1] := HexSymbols[1 + bin[i] and $0F];
  end;
end;

I am unsure how to convert it back into an array of byte properly. I am shooting for something like the following:

Type TDCArray = Array of Byte;

function xHexToBin(const HexStr: String): TDCArray;
const HexSymbols = '0123456789ABCDEF';
var i: integer;
begin
  SetLength(Result, ???); //Need to now get half of the length, unsure how to go about that
  for i :=  0 to Length(HexStr)-1 do begin
    //Here convert back into an array somehow...
    //Result[i] := ???
  end;
end;

How would I go about doing this?

Also, I am using Delphi XE2.

  • 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-06-13T13:52:35+00:00Added an answer on June 13, 2026 at 1:52 pm

    If you want to do it yourself:

    function xHexToBin(const HexStr: String): TBytes;
    const HexSymbols = '0123456789ABCDEF';
    var i, J: integer;
        B: Byte;
    begin
      SetLength(Result, (Length(HexStr) + 1) shr 1);
      B:= 0;
      i :=  0;
      while I < Length(HexStr) do begin
        J:= 0;
        while J < Length(HexSymbols) do begin
          if HexStr[I + 1] = HexSymbols[J + 1] then Break;
          Inc(J);
        end;
        if J = Length(HexSymbols) then ; // error
        if Odd(I) then
          Result[I shr 1]:= B shl 4 + J
        else
          B:= J;
        Inc(I);
      end;
      if Odd(I) then Result[I shr 1]:= B;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a byte array that I'm encoding to a string: Private Function GetKey()
I have a byte array which needs to be marshalled into the following struct:
i have a very long hex string in a byte array and I would
I have a byte array that contains list of unicode strings. Each string is
I have a byte array that has hex values and I initially put those
I've got a byte array that was created using a hash function. I would
I have byte array as input. I would like to convert that array to
I have a byte array that may or may not have null bytes at
I have an SHA-1 byte array that I would like to use in a
I have a byte that is an array of 30 bytes, but when I

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.