Click here to Skip to main content
15,905,781 members
Home / Discussions / C#
   

C#

 
GeneralRe: database connection problem Pin
MNantu6-Dec-09 23:20
MNantu6-Dec-09 23:20 
GeneralRe: database connection problem Pin
Erdinc276-Dec-09 23:43
Erdinc276-Dec-09 23:43 
GeneralRe: database connection problem Pin
lalit147-Dec-09 0:01
lalit147-Dec-09 0:01 
GeneralRe: database connection problem Pin
lalit147-Dec-09 0:10
lalit147-Dec-09 0:10 
GeneralRe: database connection problem Pin
Erdinc277-Dec-09 0:14
Erdinc277-Dec-09 0:14 
GeneralRe: database connection problem Pin
MNantu7-Dec-09 0:40
MNantu7-Dec-09 0:40 
GeneralRe: database connection problem Pin
Erdinc277-Dec-09 1:19
Erdinc277-Dec-09 1:19 
QuestionConverting BitArray to string Pin
Joe Rozario6-Dec-09 21:37
Joe Rozario6-Dec-09 21:37 
Dear Friends,

i have small problem

can U please tell where do i make mistake?

i am converting string value "0000000000000001" to byte array

then again i am converting back byte array to string

the out put is like these "0000000010000000"

private void button14_Click(object sender, EventArgs e)
{
//i am converting string value "0000000000000001" to byte array
string sVall = "0000000000000001";
byte[] bVal =convertBinaryToByte(sVall, 8);

//then again i am converting back byte array to string

BitArray objBitA = new BitArray(bVal);
MessageBox.Show(converBitArrayTostring(objBitA));

}



private string converBitArrayTostring(BitArray objBit)
{
try
{
string sReturnValue = "";
for (int i = 0; i < objBit.Length; i++)
{
sReturnValue += (objBit[i]) ? "1" : "0";
}
return sReturnValue;
}
catch
{
return "";
}
}



private byte[] convertBinaryToByte(string binary, int bitsPerByte)
{
try
{
List<byte> list = new List<byte>();
for (int i = 0; i < binary.Length; i += bitsPerByte)
{
string t = binary.Substring(i, bitsPerByte);

//list.Add(Convert.ToByte(t, 2));
list.Add(Convert.ToByte(t));
}
return list.ToArray();
}
catch
{
return new byte[0];
}
}


please point out my mistake..

is there any othere better method to do this?

help me

by

joe
AnswerRe: Converting BitArray to string Pin
dan!sh 6-Dec-09 21:45
professional dan!sh 6-Dec-09 21:45 
GeneralRe: Converting BitArray to string Pin
Joe Rozario6-Dec-09 21:55
Joe Rozario6-Dec-09 21:55 
AnswerRe: Converting BitArray to string Pin
shiplu_20506-Dec-09 22:27
shiplu_20506-Dec-09 22:27 
GeneralRe: Converting BitArray to string Pin
Joe Rozario6-Dec-09 22:32
Joe Rozario6-Dec-09 22:32 
AnswerRe: Converting BitArray to string Pin
OriginalGriff6-Dec-09 23:17
mveOriginalGriff6-Dec-09 23:17 
AnswerRe: Converting BitArray to string Pin
Luc Pattyn7-Dec-09 0:36
sitebuilderLuc Pattyn7-Dec-09 0:36 
GeneralRe: Converting BitArray to string Pin
Joe Rozario7-Dec-09 7:27
Joe Rozario7-Dec-09 7:27 
QuestionCPU Load of a MDI-Child Pin
DrNokill6-Dec-09 19:39
DrNokill6-Dec-09 19:39 
QuestionCustomize Quick Access Toolbar for MS Office 2007 applications Pin
Dumb Programmer6-Dec-09 18:34
Dumb Programmer6-Dec-09 18:34 
Questioncrawling a data of a website Pin
uglyeyes6-Dec-09 14:35
uglyeyes6-Dec-09 14:35 
AnswerRe: crawling a data of a website Pin
Mycroft Holmes6-Dec-09 18:48
professionalMycroft Holmes6-Dec-09 18:48 
QuestionBuiltin function for getting all ip addresses? Pin
Jacob Dixon6-Dec-09 14:23
Jacob Dixon6-Dec-09 14:23 
AnswerRe: Builtin function for getting all ip addresses? Pin
Dave Kreskowiak6-Dec-09 15:46
mveDave Kreskowiak6-Dec-09 15:46 
AnswerRe: Builtin function for getting all ip addresses? Pin
Jacob Dixon6-Dec-09 16:59
Jacob Dixon6-Dec-09 16:59 
GeneralRe: Builtin function for getting all ip addresses? Pin
Mycroft Holmes6-Dec-09 18:50
professionalMycroft Holmes6-Dec-09 18:50 
Questionget file name (only) Pin
tamir9016-Dec-09 10:22
tamir9016-Dec-09 10:22 
AnswerRe: get file name (only) Pin
Blue_Boy6-Dec-09 10:29
Blue_Boy6-Dec-09 10:29 

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.