0

重複の可能性:
BitArray を単一の int に変換するにはどうすればよいですか?

整数をaに読み取る方法BitArray(6)(含まれていると仮定)と、aBitArray(6)を符号なし/符号付き整数に変換する方法。

4

2 に答える 2

1
byte[] bytes = { 0, 0, 0, 25 };

// If the system architecture is little-endian (that is, little end first),
// reverse the byte array.
if (BitConverter.IsLittleEndian)
    Array.Reverse(bytes);

int i = BitConverter.ToInt32(bytes, 0);
Console.WriteLine("int: {0}", i);
// Output: int: 25
于 2011-11-15T23:43:16.887 に答える
0
BitArray FromInt32(Int32 a)
{
    byte[] bytes = BitConverter.GetBytes(a);
    return new BitArray(bytes);
}

逆操作については、前述のようにこの質問を参照してください。

于 2011-11-15T23:44:58.217 に答える