Click here to Skip to main content
15,896,606 members
Home / Discussions / C#
   

C#

 
QuestionInterface Colllection Pin
Isaac Gordon28-Dec-09 19:15
Isaac Gordon28-Dec-09 19:15 
AnswerRe: Interface Colllection Pin
Abhinav S28-Dec-09 19:23
Abhinav S28-Dec-09 19:23 
QuestionDragging to Resize A Control Pin
Roger Wright28-Dec-09 19:09
professionalRoger Wright28-Dec-09 19:09 
AnswerRe: Dragging to Resize A Control Pin
dan!sh 28-Dec-09 19:26
professional dan!sh 28-Dec-09 19:26 
QuestionHello Pin
levan omadze28-Dec-09 19:08
levan omadze28-Dec-09 19:08 
AnswerRe: Hello Pin
Roger Wright28-Dec-09 19:21
professionalRoger Wright28-Dec-09 19:21 
AnswerRe: Hello Pin
dan!sh 28-Dec-09 19:32
professional dan!sh 28-Dec-09 19:32 
QuestionHello Pin
levan omadze28-Dec-09 19:05
levan omadze28-Dec-09 19:05 
QuestionHow to store PIXEL VALUES in ARRAY? Pin
meetmak28-Dec-09 18:54
meetmak28-Dec-09 18:54 
AnswerRe: How to store PIXEL VALUES in ARRAY? Pin
dan!sh 28-Dec-09 19:21
professional dan!sh 28-Dec-09 19:21 
GeneralRe: How to store PIXEL VALUES in ARRAY? Pin
meetmak29-Dec-09 1:14
meetmak29-Dec-09 1:14 
GeneralRe: How to store PIXEL VALUES in ARRAY? Pin
dan!sh 29-Dec-09 3:32
professional dan!sh 29-Dec-09 3:32 
AnswerRe: How to store PIXEL VALUES in ARRAY? Pin
Abhinav S28-Dec-09 19:27
Abhinav S28-Dec-09 19:27 
GeneralRe: How to store PIXEL VALUES in ARRAY? Pin
meetmak29-Dec-09 1:12
meetmak29-Dec-09 1:12 
GeneralRe: How to store PIXEL VALUES in ARRAY? Pin
meetmak29-Dec-09 1:13
meetmak29-Dec-09 1:13 
AnswerRe: How to store PIXEL VALUES in ARRAY? Pin
Keith Barrow29-Dec-09 0:00
professionalKeith Barrow29-Dec-09 0:00 
GeneralRe: How to store PIXEL VALUES in ARRAY? Pin
meetmak29-Dec-09 1:08
meetmak29-Dec-09 1:08 
QuestionError while declaring Interfaces regarding HRESULT Pin
giji gangadharan28-Dec-09 17:20
giji gangadharan28-Dec-09 17:20 
AnswerRe: Error while declaring Interfaces regarding HRESULT Pin
Ben Fair29-Dec-09 3:58
Ben Fair29-Dec-09 3:58 
QuestionChanging registry settings through .Net app Pin
Anindya Chatterjee28-Dec-09 17:02
Anindya Chatterjee28-Dec-09 17:02 
AnswerRe: Changing registry settings through .Net app Pin
Giorgi Dalakishvili28-Dec-09 19:02
mentorGiorgi Dalakishvili28-Dec-09 19:02 
GeneralRe: Changing registry settings through .Net app Pin
Anindya Chatterjee29-Dec-09 5:33
Anindya Chatterjee29-Dec-09 5:33 
QuestionHelp in calling a Delegate from Library Pin
MAW3028-Dec-09 15:07
MAW3028-Dec-09 15:07 
AnswerRe: Help in calling a Delegate from Library Pin
Luc Pattyn28-Dec-09 15:31
sitebuilderLuc Pattyn28-Dec-09 15:31 
QuestionIs there a way to write an bit to a binary file (NOT a byte) in C# ? [modified] Pin
Alex Manolescu28-Dec-09 13:26
Alex Manolescu28-Dec-09 13:26 
Hello,
i'll try to be concret on my problem.

I want to convert a string: "alex" to bits (by bits I mean 0 and 1) and then write them into a binary file.
There are many ways to do this, but i've selected this:
private void MyWriteMethod()
{

byte[] bytes = UTF8Encoding.Default.GetBytes("alex");
Stream str = File.Create("test.bin");

          BinaryWriter bw = new BinaryWriter(str);
          BitArray bits = new BitArray(bytes);

          for (int i = 0; i < bits.Length; i++)
          {              

                  bw.Write(bits.Get(i)); // the method Get of class BitArray returns the bit (true or false)
                                         // from the position recived as parameter.
          }
}


My problem is:
All goes well, but when I look for my file it occurs 32 bytes on my HDD.
Now to do a comparison, I create a new file and write by hand the text "alex". When I look for this new created file, I see that it occurs 4 bytes!!!!

My questions are:
1. Why is that ?? Can anyone explain to me this phenomenon ??
2. Can I occure the same amount of bytes using the bits ?
3. Afther that may I recive a code sample on how this can be done? I mean: how can I write bits to a binary file?

Thanks you for you're patience!
Alex Manolescu.

modified on Tuesday, December 29, 2009 3:58 AM

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.