BitConverter

Most base types can be converted to a byte array, by calling BitConverter.GetBytes:


using System;
using System.Text;
using System.Globalization;

class Sample
{
    public static void Main()
    {
        foreach (byte b in BitConverter.GetBytes(3.5))
            Console.Write(b + " ");  // 0 0 0 0 0 0 12 64
    }
}

The output:


0 0 0 0 0 0 12 64

BitConverter also provides methods for converting in the other direction, such as ToDouble.

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.