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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:10:39+00:00 2026-06-09T03:10:39+00:00

I am trying to make a program that writes the binary code of a

  • 0

I am trying to make a program that writes the binary code of a file in a separate text file.

When I use this program on a text file, it doesn’t write anything in the new file. I then tested this for .jpg and .mp3 files and the program seems to write most of the binary code but leaves out the last couple of bytes. Here is my code:

Sub Main()
    Console.Write("Filename:  ")
    Dim Filename As String = Console.ReadLine()
    Console.Write("Extension: ")
    Dim Extension As String = Console.ReadLine()
    Console.WriteLine()

    Dim Stream_1 As FileStream = New FileStream(Filename & "." & Extension, FileMode.Open)
    Dim Stream_2 As FileStream = New FileStream(Filename & "_b.txt", FileMode.Create)

    Dim Reader_1 As BinaryReader = New BinaryReader(Stream_1)
    Dim Writer_2 As StreamWriter = New StreamWriter(Stream_2)

    Dim File_Bytes() As Byte = Reader_1.ReadBytes(Convert.ToInt32(Stream_1.Length))

    Dim Binary_String As String = ""

    'These are used to a add line break after every 8 bytes
    Dim Binary_String_Collection As String = ""
    Dim Counter As Integer

    For Each File_Byte In File_Bytes
        Counter += 1

        Binary_String = Convert.ToString(File_Byte, 2)

        For I = 1 To 8 - Binary_String.Length
            Binary_String = "0" & Binary_String
        Next

        Binary_String_Collection = Binary_String_Collection & Binary_String & " "

        If Counter = 8 Then
            Writer_2.WriteLine(Binary_String_Collection)

            Counter = 0
            Binary_String_Collection = ""
        End If
    Next

    If Binary_String_Collection <> "" Then
        Writer_2.WriteLine(Binary_String_Collection)
    End If

    Console.ReadLine()
End Sub

At first I thought that my program wasn’t reading the binary code properly so I added console outputs at locations where it writes to the file. The program displayed correct output so I’m confused why it isn’t writing properly.

  • 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-09T03:10:41+00:00Added an answer on June 9, 2026 at 3:10 am

    Make sure you close the file and Dispose of the streams correctly.

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

Sidebar

Related Questions

I'm trying to write a program that will take an HTML file and make
I am trying to write a program that will take a text file with
I am trying to make a program that can take an .mp3 file from
I'm trying to write a program that modifies fractions and I need to make
I'm trying to write a basic Erlang program that reads in a file in
So I'm trying to make my program output a text file with a list
I'm trying to write a simple high-low program that will output like this: $
I'm trying to make a program that will open a directory, then use regular
Im trying to make a program that retrieves an endless amount of numbers that
I'm trying to make a program that, using pointers, detects lines in an image

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.