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

The Archive Base Latest Questions

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

Serialization: bool[] tempArray = new bool[MapWidth * MapHeight]; for (int i = 0; i

  • 0

Serialization:

            bool[] tempArray = new bool[MapWidth * MapHeight];
            for (int i = 0; i < MapWidth; i++)
            {
                for (int ii = 0; ii < MapHeight; ii++)
                {
                    tempArray[i * ii] = mapSolid[i, ii];
                }
            }
            BitArray bits = new BitArray(tempArray);
            byte[] bytes = new byte[32 * MapWidth];
            bits.CopyTo(bytes, 0);
            bin.Serialize(stream, Convert.ToBase64String(bytes));

Desrialization:

byte[] bytes = new byte[255 * 255];
                    bytes=Convert.FromBase64String((string)bin.Deserialize(stream));
                    //mapSolid = ;
                    MapWidth = (int)bin.Deserialize(stream);
                    MapHeight = (int)bin.Deserialize(stream);
                    BitArray bits = new BitArray(bytes);
                    bool[] bytestemp = new bool[255*265];
                    bits.CopyTo(bytestemp, 0);
                    for (int i = 0; i < MapWidth; i++)
                    {
                        for (int ii = 0; ii < MapHeight; ii++)
                        {
                            mapSolid[i, ii] = bytestemp[i*ii];
                        }
                    }

Now everything seems to work without errors but the map looses it’s structure after deserialization.

  • 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-13T08:52:54+00:00Added an answer on June 13, 2026 at 8:52 am
    tempArray[i * ii]
    

    and

    bytestemp[i * ii]
    

    is wrong; that index should be something like:

    (i * MapWidth) + ii
    

    or

    i + (ii * MapHeight)
    

    depending on whether you are writing rows-first or columns-first.

    Otherwise, for example, the cells {1,4} and {4,1} would be stored in the same place.

    If you want to avoid the math, another common approach is just:

    int offset = 0;
    for (int i = 0; i < MapWidth; i++)
    {
        for (int ii = 0; ii < MapHeight; ii++)
        {
            tempArray[offset++] = mapSolid[i, ii];
        }
    }
    

    and

    int offset = 0;
    for (int i = 0; i < MapWidth; i++)
    {
        for (int ii = 0; ii < MapHeight; ii++)
        {
            mapSolid[i, ii] = bytestemp[offset++];
        }
    }
    

    i.e. just read/write from/to “the next position” each time. Just make sure the read and write loop agree on which is the outer/inner loop (they seem to).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If i try to serialize an object of the following ClassToSerialize class with System.Runtime.Serialization.Json.DataContractJsonSerializer
i am trying to serialize a field of my class. Withou it serialization is
I'm running a desktop application and when I reach this line: serializer.Serialize(new StringWriter(sb), value);
I'm new to serialization, so most likely I am missing something obvious! I have
In serialization mechanism,we are wrote the object into stream using objectinputstream and object outputstream.These
using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; VS says, The type or namespace name 'Formatters' does not
I am using xml serialization and de-serialization to read and write to an XML
I'm going through serialization and I can't understand the following: I don't understand why
There is simple JSON serialization module with name simplejson which easily serializes Python objects
I am currently using Serialization in order to make deep copies of some autogenerated

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.