У меня есть логический список с 92 логическими значениями, я хочу, чтобы список был преобразован в строку, я подумал, что возьму 8 логических (битов) и помещу их в байт (8 бит), а затем использую ASCII для преобразования это байтовое значение для символа, затем добавьте символы в строку. Однако после того, как погуглил более 2 часов, банкомат не повезло. Я попытался преобразовать список в список байтов, но это тоже не сработало ^^.
String strbyte = null;
for (int x = 0; x != tmpboolist.Count; x++) //tmpboolist is the 90+- boolean list
{
//this loop checks for true then puts a 1 or a 0 in the string(strbyte)
if (tmpboolist[x])
{
strbyte = strbyte + '1';
}
else
{
strbyte = strbyte + '0';
}
}
//here I try to convert the string to a byte list but no success
//no success because the testbytearray has the SAME size as the
//tmpboolist(but it should have less since 8 booleans should be 1 Byte)
//however all the 'Bytes' are 48 & 49 (which is 1 and 0 according to
//http://www.asciitable.com/)
Byte[] testbytearray = Encoding.Default.GetBytes(strbyte);
PS Есть ли у кого-нибудь лучшее предложение о том, как кодировать и декодировать логический список в строку? (Потому что я хочу, чтобы люди делились своим логическим списком строкой, а не списком из 90 единиц и нулей.)
РЕДАКТИРОВАТЬ: теперь все работает! ty all за помощь
string text = new string(tmpboolist.Select(x => x ? '1' : '0').ToArray());
byte[] bytes = getBitwiseByteArray(text); //http://stackoverflow.com/a/6756231/1184013
String Arraycode = Convert.ToBase64String(bytes);
System.Windows.MessageBox.Show(Arraycode);
//first it makes a string out of the boolean list then it uses the converter to make it an Byte[](array), then we use the base64 encoding to make the byte[] a String.(that can be decoded later)
Я посмотрю на encoding32 позже, ty за помощью снова :)