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 436581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:29:32+00:00 2026-05-12T20:29:32+00:00

I have The following code for now. type TByte4 = array[0..3] of Byte; //

  • 0

I have The following code for now.

type
  TByte4 = array[0..3] of Byte; // 32-bit

function CardinalToBytes(const Data: Cardinal): TByte4;
begin
  Result[0] := (Data shr 24) and 255;
  Result[1] := (Data shr 16) and 255;
  Result[2] := (Data shr 8) and 255;
  Result[3] := Data and 255;
end;

function BytesToCardinal(const Data: TByte4): Cardinal;
begin
  Result := (Data[0] * 16777216) +
            (Data[1] * 65536) +
            (Data[2] * 256) +
             Data[3];
end;

I am wondering if this is the fastest and most efficient way (I am sure it is not 🙂 ). The catch is this has to work in compact framework under Delphi 2006 (don’t even ask).
I am using it in a TEA encryption algorithm that works with Ansi and Unicode versions of Delphi and also with .NET and .NET compact framework in Delphi 2006.

So no “Move” and similar functions that work with pointers are allowed (no i do not want unsafe code).

Edit:

I still haven’t found a better way to do this. Some great suggestion were given, but they all fail in .NET. I am afraid I will not spend any more time on a dead road. VCL .NET is dead, so is CF in delphi I am afraid. So this will have to do for maintaining this project. I will stil wait for while if somebody proves me wrong and gets the code to compile in .NET

Edit2:

The solution was simple as it is in most cases. Somebody just had to look for the obvious solution. I just didn’t know anymore that there is a BitConverter class in .NET

  • 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-12T20:29:33+00:00Added an answer on May 12, 2026 at 8:29 pm

    In Delphi.NET, use the BitConverter class from the .NET framework to do the conversion. See BitConverter Class (System).

    For an example:

    function CardinalToBytes(const Data: Cardinal): TBytes;
    begin
      Result := BitConverter.ToBytes(Data);
    end;
    
    function BytesToCardinal(const Data: TBytes): Cardinal;
    begin
      Result := BitConverter.ToUInt32(Data, 0);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 227k
  • Answers 227k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You might try the EVE Online database dumps. May 13, 2026 at 1:18 am
  • Editorial Team
    Editorial Team added an answer Try this: re.sub(r'([aeiou])\1', r'\1:', str) May 13, 2026 at 1:18 am
  • Editorial Team
    Editorial Team added an answer if you have a database entity corresponding to one page… May 13, 2026 at 1:18 am

Related Questions

I'm working on creating a domain layer in Zend Framework that is separate from
I have a simple HTML. I am using the JQuery for AJAX purpose. Now,
I would like to use Cocos2d on the iPhone to draw a 2D car
I am trying to write a PHP script that can upload multiple files. for($i=0;$i<count($_FILES['uploadimg']['name']);$i++){

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.