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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:22:32+00:00 2026-06-01T15:22:32+00:00

Ok, I need to store/retrieve a bit from a data table of 3.268.760 bits

  • 0

Ok, I need to store/retrieve a bit from a data table of 3.268.760 bits long.

Using w As New BinaryWriter(File.Open("test.bin", FileMode.Create))
    for x = 1 to 3268760
        For i = 1 To 3268760
            w.Write(countBits(bitLikeness(u(i), u(x))) > 10)
        Next
     Next
End Using

the w.write(?) stores a boolean value meaning 0/1 for false/true values, but Vb.net seems to use an whole byte to store this data which is too expensive for my table (3.268.760^2)

Is there a pratical way to store/retrive single bits from a file using vb.net? (meaning as little as possible conversion to other types).

  • 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-01T15:22:34+00:00Added an answer on June 1, 2026 at 3:22 pm

    Wrapping the BinaryReader/Writer is probably your best option.

    Public Class BitWriter
    
        Private ReadOnly mBinaryWriter As BinaryWriter
    
        Private mBuffer As Integer
        Private mBufferCount As Integer
    
        Public Sub New(binaryWriter As BinaryWriter)
            mBinaryWriter = binaryWriter
        End Sub
    
        Public Sub WriteBit(bit As Boolean)
    
            If mBufferCount = 32 Then
    
                mBinaryWriter.Write(mBuffer)
    
                mBuffer = 0
                mBufferCount = 0
    
            End If
    
            If bit Then mBuffer = mBuffer Or (1 << mBufferCount)
    
            mBufferCount += 1
    
        End Sub
    
        Public Sub Flush()
    
            mBinaryWriter.Write(mBuffer)
    
            mBuffer = 0
            mBufferCount = 0
    
        End Sub
    
    End Class
    

    And to read the bits back

    Public Class BitReader
    
        Private ReadOnly mBinaryReader As BinaryReader
    
        Private mBuffer As Integer
        Private mBufferCount As Integer
    
        Public Sub New(binaryReader As BinaryReader)
            mBinaryReader = binaryReader
            mBuffer = -1
        End Sub
    
        Public Function ReadBit() As Boolean
    
            If mBuffer = -1 OrElse mBufferCount = 8 Then
    
                mBuffer = mBinaryReader.ReadInt32()
                mBufferCount = 0
    
            End If
    
            Dim toReturn As Boolean = ((mBuffer >> mBufferCount) And 1) = 1
    
            mBufferCount += 1
    
            Return toReturn
    
        End Function
    
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to store a lot of data coming in from a server into
I'd like a bit of advice on how to retrieve, process and store data.
I need to store some sensitive data by encrypting it with atleast 128 bit
The project I have been given is to store and retrieve unstructured data from
I have a IQueryable function. In that function, I need to store and retrieve
I've come to the point where I need to store some additional data about
I am a bit new to Perl and I need some help regarding moving
I'm making a game in c++ that will need to store and retrieve information
I need to store different objects in IsolatedStorage and i'm using IsolatedStorageSettings class to
The problem: I need to be able to recursively retrieve a node from a

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.