Answer the question
In order to leave comments, you need to log in
Reading a C# file?
I apologize for the stupid question, but it's kind of hard to understand how bit by bit is read in C#. I found this code on the Internet, can you help me figure out what's going on here?
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace hdlc_ip
{
class Program
{
static void Main(string[] args)
{
FileStream file = new FileStream("C:\\1.txt",
FileMode.Open, FileAccess.Read);
byte[] buf = new byte[1024];
int r = -1;
byte b;
while (r != 0)
{
r = file.Read(buf, 0, buf.Length);
for (int j = 0; j < r; j++)
{
b = buf[j];
for (int i = 7; i >= 0; i--)
Console.Write((b >> i) & 1);
Console.Write((j + 1) % 4 == 0 ? '\n' : ' ');
}
}
file.Close();
Console.ReadKey(true);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question