Possible Duplicate:
How i can convert BitArray to single int?
How can I read an integer to a BitArray(6) (assuming it can be contained) and how to convert a BitArray(6) to unsigned/signed integer.
Possible Duplicate:
How i can convert BitArray to single int?
How can I read an integer to a BitArray(6) (assuming it can be contained) and how to convert a BitArray(6) to unsigned/signed integer.
 
    
     
    
    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
 
    
    BitArray FromInt32(Int32 a)
{
    byte[] bytes = BitConverter.GetBytes(a);
    return new BitArray(bytes);
}
For reverse operaton see this question as mentioned before.
 
    
    