Write Double value as Big-endian using FileStream - CSharp System.IO

CSharp examples for System.IO:FileStream

Description

Write Double value as Big-endian using FileStream

Demo Code


using System.Linq;
using System.IO;/*  w w w. j a v  a2  s. c  o m*/
using System.Text;
using System.Collections.Generic;
using System;

public class Main{
        /// <summary>
        /// Write Double value as Big-endian
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="value"></param>
        public static void WriteDouble(FileStream stream,double value)
        {

            var byteArray = BitConverter.GetBytes(value);

            //Big endian
            stream.Write((BitConverter.IsLittleEndian) ? byteArray.Reverse().ToArray() : byteArray,
                0, byteArray.Length);
        }
}

Related Tutorials