April 2002
Intermediate to advanced
1024 pages
23h 26m
English
This class has a number of methods that convert from raw (unmanaged) data to managed data types. Listing B.1 shows an example of converting from a byte array to an integer (bitconverter.cs).
static void Main(string [] args)
{
byte [] rawData = new byte [] {1,2,3,4} ;
int convertedInt = BitConverter.ToInt32(rawData, 0);
Console.WriteLine("Raw data: {0} {1} {2} {3} ",
rawData[0],
rawData[1],
rawData[2],
rawData[3]);
Console.WriteLine("Converted data: {0} 0x{0:X} ",
convertedInt);
}
|
The output for this application looks like this:
Raw data: 1234 Converted data: 67305985 0x4030201