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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:58:41+00:00 2026-06-03T04:58:41+00:00

I would like to know how to manipulate bits from a ByteArray. What I

  • 0

I would like to know how to manipulate bits from a ByteArray.
What I need is to shift the bits according to a ‘table’ that I have.

Table:

Bit 0 -> Bit 26
Bit 1 -> Bit 31
Bit 2 -> Bit 17
...
Bit 31 -> Bit 5

I convert the ByteArray to BitArray using this method

public static BitArray ByteArraytoBitArray(byte[] bytes)
{
    BitArray bits = new BitArray(bytes);
    return bits;
}

But I am stuck there, I don’t know how to shift the bits according to the table and then back to ByteArray.

EDIT:

Code Snipet:

public static byte[] StringToByteArray(String hex)
{
    int NumberChars = hex.Length;
    byte[] bytes = new byte[NumberChars / 2];
    for (int i = 0; i < NumberChars; i += 2)
        bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
    return bytes;
}
private void button3_Click(object sender, EventArgs e)
{
    string featherearring = "00804804A02A1CA20100000000000000D2F8B6FABBB700000000000000000000";
    var strarray = StringToByteArray(featherearring);

    byte[] strarray_comp = Enc.Encrypt(strarray);

    string conv = BitConverter.ToString(strarray_comp);
    MessageBox.Show(conv.Replace("-", ""));
}



public static byte[] BitArrayToByteArray(BitArray bits)
{
    byte[] bytes = new byte[bits.Length / 8];
    bits.CopyTo(bytes, 0);
    return bytes;
}
public static byte[] Encrypt(byte[] input)
{
    BitArray source = new BitArray(input);
    BitArray target = new BitArray(source.Length);

    target[26] = source[0];
    target[31] = source[1];
    target[17] = source[2];
    target[10] = source[3];
    target[30] = source[4];
    target[16] = source[5];
    target[24] = source[6];
    target[2] = source[7];
    target[29] = source[8];
    target[8] = source[9];
    target[20] = source[10];
    target[15] = source[11];
    target[28] = source[12];
    target[11] = source[13];
    target[13] = source[14];
    target[4] = source[15];
    target[19] = source[16];
    target[23] = source[17];
    target[0] = source[18];
    target[12] = source[19];
    target[14] = source[20];
    target[27] = source[21];
    target[6] = source[22];
    target[18] = source[23];
    target[21] = source[24];
    target[3] = source[25];
    target[9] = source[26];
    target[7] = source[27];
    target[22] = source[28];
    target[1] = source[29];
    target[25] = source[30];
    target[5] = source[31];

    return BitArrayToByteArray(target);
}

my input byte array is “00804804A02A1CA20100000000000000D2F8B6FABBB700000000000000000000” and my output with zimdanen’s code is “5012000000000000000000000000000000000000000000000000000000000000” and it should be “501200002FD901000000000400000000BFE8C4DB140D11F40000000000000000”
As you can see, it gets the first 2 bytes right, but the rest is are all null.

  • 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-03T04:58:43+00:00Added an answer on June 3, 2026 at 4:58 am

    Does it need to be in place? You can create a new BitArray and just copy the bits over:

    BitArray source = new BitArray(bytes);
    
    // Create target array.
    BitArray target = new BitArray(source.Length);
    
    // Map bits.
    // ...
    target[26] = source[0];
    // ...
    

    Or, depending on how you want to maintain your mapping “table”, you can do it like this:

    // Setup mapping - <source, target>.
    Dictionary<int, int> mapping = new Dictionary<int, int>();
    // ...
    mapping.Add(0, 26);
    // ...
    
    BitArray source = new BitArray(bytes);
    
    // Create target array.
    BitArray target = new BitArray(source.Length);
    
    // Map bits.
    foreach (int sourceIndex in mapping.Keys)
    {
        int targetIndex = mapping[sourceIndex];
        target[targetIndex] = source[sourceIndex];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know the reasons that we do refactoring and justify it.
I would like to know whether it is possible to write code that would
I have some html which I would like to manipulate. Its structure is as
I would like to know if a class exists to manipulate date with symfony
I have a query that is basically like this: SELECT foo FROM bar where
String xpath = //center/div; I would like to manipulate the above string so that
i would like know some reference. I know i can googling it. but prefer
Would like to know what a programmer should know to become a good at
Would like to know the c# code to actually retrieve the IP type: Static
Would like to know how to integarate cruise control with maven? Cruise Control comes

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.