Skip to Content
.NET Common Language Runtime Unleashed
book

.NET Common Language Runtime Unleashed

by Kevin Burton
April 2002
Intermediate to advanced content levelIntermediate to advanced
1024 pages
23h 26m
English
Sams
Content preview from .NET Common Language Runtime Unleashed

System.BitConverter

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).

Listing B.1. System.BitConverter Sample
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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Customizing the Microsoft® .NET Framework Common Language Runtime

Customizing the Microsoft® .NET Framework Common Language Runtime

Steven Pratschner

Publisher Resources

ISBN: 0672321246Purchase book