Read Double value as Big-endian from FileStream - CSharp System.IO

CSharp examples for System.IO:FileStream

Description

Read Double value as Big-endian from FileStream

Demo Code


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

public class Main{
        /// <summary>
        /// Read Double value as Big-endian
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static double ReadDouble(FileStream stream)
        {
            var length = sizeof(double);
            var buf = new byte[length];
            stream.Read(buf, 0, length);

            var value = BitConverter.ToDouble((BitConverter.IsLittleEndian) ? buf.Reverse().ToArray() : buf, 0);

            return value;
        }
}

Related Tutorials