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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:58:10+00:00 2026-05-30T21:58:10+00:00

Case : Again trying to capture packets through my NIC, I have developed 2

  • 0

Case :
Again trying to capture packets through my NIC,
I have developed 2 Extensions to use in capturing variable number of bits

    public static string ReadBits ( this BinaryReader Key , int Value )
    {
        BitArray _BitArray = new BitArray ( Value );

        for ( int Loop = 0 ; Loop > Value ; Loop++ )
        {
/* Problem HERE ---> */   _BitArray [ Loop ] = Key . ReadBoolean ( );
        }

        return BitConverter . ToString ( _BitArray . ToByteArray ( ) );
    }

    public static byte [ ] ToByteArray ( this BitArray Key )
    {
        byte [ ] Value = new byte [ ( int ) Math . Ceiling ( ( double ) Key . Length / 8 ) ];
        Key . CopyTo ( Value , 0 );
        return Value;
    }

Problem :

_BitArray [ Loop ] = Key . ReadBoolean ( );  

As I’m trying to read single bits, but referring to MSDN Documentation,
It advances the stream position by 1 BYTE not 1 BIT !!!

Reads a Boolean value from the current stream and advances the current
position of the stream by one byte.

Question :
Can I really capture “ONLY” 1 Bit & advance the stream position by 1 Bit ?
Please suggest me solutions or ideas 🙂

Regards,

  • 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-30T21:58:12+00:00Added an answer on May 30, 2026 at 9:58 pm

    No, Stream positioning is based on byte step. You can write your own stream implementation with bit positioning.

    class BitReader
    {
        int _bit;
        byte _currentByte;
        Stream _stream;
        public BitReader(Stream stream)
        { _stream = stream; }
    
        public bool? ReadBit(bool bigEndian = false)
        {
          if (_bit == 8 ) 
          {
    
            var r = _stream.ReadByte();
            if (r== -1) return null;
            _bit = 0; 
            _currentByte  = (byte)r;
          }
          bool value;
          if (!bigEndian)
             value = (_currentByte & (1 << _bit)) > 0;
          else
             value = (_currentByte & (1 << (7-_bit))) > 0;
    
          _bit++;
          return value;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this case <WrapPanel> <CheckBox>Really long name</CheckBox> <CheckBox>Short</CheckBox> <CheckBox>Longer again</CheckBox> <CheckBox>Foo</CheckBox> <Slider MinWidth=200
The original use case: This is a possible use case I'm trying to solve:
I have used: [UIApplication sharedApplication].idleTimerDisabled = YES; in a number of Apps developed and
I have been trying to make a case for using Python at my work.
Again and again I have the case that during development, the Android SDK suddenly
I am trying to use localStorage to save an array of strings. I have
Case example: I have a long list of items, and when I put my
Case One Say you have a little class: class Point3D { private: float x,y,z;
The case goes as following: You have a Boolean property called FullScreenEnabled. You enter
Use case: A does something on his box and gots stuck. He asks B

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.