-5

私は学校のためのプログラム、D-FlipFlopを作らなければなりません。Dとe/clockを入力するには、2つのテキストボックスを使用します。(また、AND、NAND、OR、NOR、XORポートを含む3つのポートでプログラムを作成する必要がありましたが、それはすでに機能しています)。

の入力は次のDとおりです。000001111100000111111100000011

の入力は次のEとおりです。000111000111000111000111000111

からの値textbox1はに移動する必要がありpictureboxます。これで、01で線を引き、フリップフロップを視覚的にすることができます。からの値textbox2はに移動する必要がありますpicturebox2

4

1 に答える 1

0

これは可能です。実際に変換する必要がある000001111100000111111100000011か、バイト配列000111000111000111000111000111として扱われます。これを行うには、stringbyte[]Convert.ToByte(object value, IFormatProvider provider)

string input = "BINARY GOES HERE";
int numOfBytes = input.Length / 8; //Get binary length and divide it by 8
byte[] bytes = new byte[numOfBytes]; //Limit the array
for (int i = 0; i < numOfBytes; ++i)
{
     bytes[i] = Convert.ToByte(input.Substring(8 * i, 8), 2); //Get every EIGHT numbers and convert to a specific byte index. This is how binary is converted :)
}

これにより、新しい文字列が宣言inputされ、バイト配列()にエンコードされますbyte[]。として使用し、に挿入byte[]できるようにするには、実際にこれが必要になります。これを行うには、StreamPictureBoxMemoryStream

MemoryStream FromBytes = new MemoryStream(bytes); //Create a new stream with a buffer (bytes)

最後に、このストリームを使用してファイルを作成しImage、ファイルをPictureBox

pictureBox1.Image = Image.FromStream(FromBytes); //Set the image of pictureBox1 from our stream

private Image Decode(string binary)
{
    string input = binary;
    int numOfBytes = input.Length / 8;
    byte[] bytes = new byte[numOfBytes];
    for (int i = 0; i < numOfBytes; ++i)
    {
        bytes[i] = Convert.ToByte(input.Substring(8 * i, 8), 2);
    }
    MemoryStream FromBinary = new MemoryStream(bytes);
    return Image.FromStream(FromBinary);
}

これを使用することで、たとえばいつでも呼び出すことができDecode(000001111100000111111100000011)、画像に変換されます。次に、このコードを使用してImagePictureBox

pictureBox1.Image = Decode("000001111100000111111100000011");

重要なお知らせ:ArgumentException was unhandled: Parameter is not valid.これは、無効なバイナリコードが原因で発生する可能性があります。

ありがとう、
これがお役に立てば幸いです:)

于 2012-10-30T21:35:22.737 に答える