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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:15:23+00:00 2026-06-07T15:15:23+00:00

I have a List<byte[]> . Each byte array is of size 16bytes. The first

  • 0

I have a List<byte[]>. Each byte array is of size 16bytes. The first 8 bytes is a binary representation of the C# long data type which I use to stop DateTimeTicks. I wonder whether there is a way to sort a bunch of byte arrays in the same order as if I sorted by the long equivalents in ascending order. Obviously its easy if each byte array is deserialized into a long and then sorted but is there a way to get away without deserialization? If not would it be possible to find a logic to convert a DateTimeTick value into a binary representation so that sorting can be performed directly on the binary by, for example by first expressing year in binary form, then month, day, hour, minute, second, millisecond,..? My goal is to skip the deserialization step because I need to send the sorted byte array over a messaging network in binary format and it currently wastes a lot of resources to have to first deserialize for sorting purpose (sorting has to be done before sending the object over the wire), then serialize it again to send it through the messaging system, then deserialize it again.

Any ideas, hints or solutions highly welcome, thank you.

Edit: I currently use the Linq OrderBy function to sort which is fast enough for my purpose and look something along those lines, performance wise. I would like to stick to Linq unless it is not possible to order by byte array, even if I provided an IComparer…

  • 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-07T15:15:24+00:00Added an answer on June 7, 2026 at 3:15 pm
            var rnd = new Random();
    
            var data = new List<byte[]>();
    
            //As long as the first 8 bytes are the long, the byte[] can be as long as you want.
            for (int i = 0; i < 10; i++)
                data.Add(BitConverter.GetBytes((ulong)rnd.Next()));
    
            //Without any 'deserialisation'
            if (BitConverter.IsLittleEndian)
                data = data.OrderBy(x => x[7]).ThenBy(x => x[6]).ThenBy(x => x[5]).ThenBy(x => x[4]).ThenBy(x => x[3]).ThenBy(x => x[2]).ThenBy(x => x[1]).ThenBy(x => x[0]).ToList();
            else  //untested, probably wrong
                data = data.OrderBy(x => x[0]).ThenBy(x => x[1]).ThenBy(x => x[2]).ThenBy(x => x[3]).ThenBy(x => x[4]).ThenBy(x => x[5]).ThenBy(x => x[6]).ThenBy(x => x[7]).ToList();
    
            //How I'd actually approach it due to simplicity.
            //data = data.OrderBy(x => BitConverter.ToUInt64(x, 0)).ToList();
    
            data.ForEach(x => Console.WriteLine(BitConverter.ToUInt64(x, 0)));
    
            Console.ReadLine();
    
            //There are other approaches of course, but at the fundamental level you're 
            //either going to 'deserialize' the long or test each byte in order.
    
    • 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 contains list of unicode strings. Each string is
I have a List<Employee> . Each Employee has a byte[] storing a picture (or
I have a binary file which I am reading to a collection of byte
Possible Duplicate: Concatenating a C# List of byte[] I have a list of byte[]
I have list of structure. I want to modify a particular data from the
I have List I want to sort Desc by Priority, which is int and
I have list of words. I type in a word misspelled. Can I query
I have list of files which contain particular patterns, but those files have been
I'm implementing some custom serialization (to byte array), and have run into a problem
I have a list of bytes that represent raw samples read in from an

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.