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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:25:17+00:00 2026-05-23T01:25:17+00:00

I’m trying to make a loop that will recurse through an array of bytes

  • 0

I’m trying to make a loop that will recurse through an array of bytes and compare them to the next one in the array (presumably using a for loop to iterate through each entry). If the two are the same I need it to increment an int variable and then continue. If the two are not the same it needs to add the int variable to a list followed by its own byte value and then it needs “adopt” this new value as its own and start the whole thing over again until the end of the array. Its a very weird thing but it needs to be done this way so I can write the int/byte pairs to a file in the right order and with the right values.

The concern here is to get the number of consecutive entries that are the same, make note of it, then move on to the next value and repeat. If for example value 3 that we encounter is the same as value 1 that’s of no concern to us. As long as we get the number of consecutive entries for value 3 we’ve done our job.

A couple other possibly helpful points.

  • The byte values could in this case span the full range 0-255.
  • The array size may be up to 150 million byte entries so efficiency is important.
  • The array size is accessible beforehand.
  • Lastly the byte array is a byte variable in a Struct.

I hope this make sense. Thanks in advance.

EDIT: Sorry if I wasn’t quite clear before and maybe I should re-title the question as well.

To clarify, I understand what I need to do here just not how to go about it. So the question I guess would be how do I loop through this comparison and then swap out what I’m comparing when I get a false return. Most importantly how do I do that when what I’m comparing could have 255 values and I’m not aware of them. I can’t really picture how to code this so I just keep sitting there staring at VS 🙂

Does that make better sense ? If not I apologize 🙂

EDIT 2: Here’s the end result I came up with if anyone cares to look at it. It was inspired by aligray’s code down below.

            int count = 0;
            byte previous = tiles[0].TileTypeId;
            List<int> typeCount = new List<int>();
            List<byte> type = new List<byte>();
            for (int i = 0; i < worldSize; i++)
            {
                byte current = tiles[i].TileTypeId;
                if (previous == current)
                {
                    count++;
                }
                else
                {
                    typeCount.Add(count);
                    type.Add(previous);
                    previous = current;
                    count = 1;
                }
            } 
  • 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-23T01:25:18+00:00Added an answer on May 23, 2026 at 1:25 am

    If I understood the question correctly, hopefully this will get you started:

    int count = 0;
    byte previous = byteArray[0];
    List<int> list = new List<int>();
    
    for (int i = 1; i < byteArray.Length; i++)
    {
        byte current = byteArray[i];
        if (previous == current)
        {
            count++;
        }
        else
        {
            list.Add(count);
            list.Add(Convert.ToInt32(current));
        }
    
        previous = current;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and

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.