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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:31:30+00:00 2026-05-28T16:31:30+00:00

This code: BitArray bits = new BitArray(new byte[] { 7 }); foreach (bool bit

  • 0

This code:

BitArray bits = new BitArray(new byte[] { 7 });
foreach (bool bit in bits)
{
    Console.WriteLine(bit ? 1 : 0);
}

Gives me the following output:

11100000

Shouldn’t it be the other way around? Like this:

00000111

I am aware that there is little and big endian, although those terms only refer to the position of bytes. As far as I know, they don’t affect bits.

  • 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-28T16:31:31+00:00Added an answer on May 28, 2026 at 4:31 pm

    The documentation for BitArray states:

    The first byte in the array represents bits 0 through 7, the second
    byte represents bits 8 through 15, and so on. The Least Significant
    Bit of each byte represents the lowest index value: ” bytes [0] & 1″
    represents bit 0, ” bytes [0] & 2″ represents bit 1, ” bytes [0] & 4″
    represents bit 2, and so on.

    When indexing bits, the convention is to start at the least significant end, which is the right side when written in binary notation. However, when enumerating the array, you start at index 0, so they are printed out left-to-right instead of right-to-left. That’s why it looks backwards.

    For example, the word 01011010 00101101 (90 45) would be indexed as:

     0  1  0  1  1  0  1  0  -  0  0  1  0  1  1  0  1
    -----------------------    -----------------------
    15 14 13 12 11 10  9  8     7  6  5  4  3  2  1  0
    

    And you would pass it to the constructor as new byte[] { 45, 90 } since you pass it least-significant first. When printed out, it would display in index order as: 1011010001011010, which is the reverse of the original binary notation.

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

Sidebar

Related Questions

When I conpile this code: BitArray bits = new BitArray(3); bits[0] = true; bits[1]
On my 64-bit machine, this C# code works: new byte[2L * 1024 * 1024
I'm writing a large bitarray to a file using this code: import bitarray bits
This code below best illustrates my problem: The output to the console (NB it
This code in JS gives me a popup saying i think null is a
this code always returns 0 in PHP 5.2.5 for microseconds: <?php $dt = new
This code loads the href into a new window and into self, why is
This code does not write anything to the console cause the collection is empty.
I am have written the following code below to encode a bitarray into custom
I have some old code like this: private int ParseByte(byte theByte) { byte[] bytes

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.