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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:29:31+00:00 2026-05-24T19:29:31+00:00

If i take a uint value = 2921803 (0x2C954B), which is really a 4

  • 0

If i take a uint value = 2921803 (0x2C954B), which is really a 4 byte package (4B 95 2C 00)
and i want to get the 16 least significant bits of the byte version of it using bitarray, how would i go about it?

This is how i am trying to do it:

byte[] bytes = BitConverter.GetBytes(value);  //4B 95 2C 00  - bytes are moved around
BitArray bitArray = new BitArray(bytes); //entry [0] shows value for 1101 0010 (bits are reversed)

At this point, i am all turned around. I did try this:

byte[] bytes = BitConverter.GetBytes(value);

Array.Reverse(bytes);
BitArray bitArray = new BitArray(bytes);

Which gave me all the bits but completely reversed, reading from [31] to [0].
ultimately, i’m expecting/hoping to get 19349 (4B 95) as my answer.

This is how i was hoping to implement the function:

private uint GetValue(uint value, int bitsToGrab, int bitsToMoveOver)
{
    byte[] bytes = BitConverter.GetBytes(value);
    BitArray bitArray = new BitArray(bytes);

    uint outputMask = (uint)(1 << (bitsToGrab - 1));
    //now that i have all the bits, i can offset, and grab the ones i want
    for (int i = bitsToMoveOver; i < bitsToGrab; i++)
    {
        if ((Convert.ToByte(bitArray[i]) & 1) > 0)
        {
            outputVal |= outputMask;
        }

        outputMask >>= 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-24T19:29:32+00:00Added an answer on May 24, 2026 at 7:29 pm

    The 16 least significant bits of 0x2C954B are 0x954B. You can get that as follows:

    int value = 0x2C954B;
    
    int result = value & 0xFFFF;
    // result == 0x954B
    

    If you want 0x4B95 then you can get that as follows:

    int result = ((value & 0xFF) << 8) | ((value >> 8) & 0xFF);
    // result == 0x4B95
    

    Try this:

    uint value = 0x002C954Bu;
    
    int reversed = Reverse((int)value);
    // reversed == 0x4B952C00;
    
    int result = Extract(reversed, 16, 16);
    // result == 0x4B95
    

    with

    int Extract(int value, int offset, int length)
    {
        return (value >> offset) & ((1 << length) - 1);
    }
    
    int Reverse(int value)
    {
        return ((value >> 24) & 0xFF) | ((value >> 8) & 0xFF00) |
               ((value & 0xFF00) << 8) | ((value & 0xFF) << 24);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a function which needs to take a UInt as a parameter. I'm
I'm working with several components that take color as a uint, but the colors
I have some code written by someone else in which some functions take arguments
I am trying to develop a software which will take a keyboard input, consume
Do uints take different amounts of memory depending on their value? Or does each
Take this code: <?php if (isset($_POST['action']) && !empty($_POST['action'])) { $action = $_POST['action']; } if
Take the following snippet: List<int> distances = new List<int>(); Was the redundancy intended by
Take a look at the ssl_requirement plugin. Shouldn't it check to see if you're
Take a .Net Winforms App.. mix in a flakey wireless network connection, stir with
Take the following two lines of code: for (int i = 0; i <

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.