From 8bd39c3cc3bb02409c5924ecbea87b6b7459d2df Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Sat, 12 Dec 2020 17:56:15 +0100 Subject: [PATCH] Added byte[].GetSingle() and byte[].GetDouble() --- ln.type/ByteArrayExtensions.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ln.type/ByteArrayExtensions.cs b/ln.type/ByteArrayExtensions.cs index 0284e13..4202192 100644 --- a/ln.type/ByteArrayExtensions.cs +++ b/ln.type/ByteArrayExtensions.cs @@ -62,6 +62,22 @@ namespace ln.type } public static uint GetUInt(this byte[] bytes, ref int offset, Endianess endianess) => BitConverter.ToUInt32(bytes.Slice(ref offset, 4).To(endianess), 0); + public static byte[] GetSingle(this byte[] bytes, ref int offset, out float value) => GetSingle(bytes, ref offset, out value, Endianess.LITTLE); + public static byte[] GetSingle(this byte[] bytes, ref int offset, out float value, Endianess endianess) + { + value = GetSingle(bytes, ref offset, endianess); + return bytes; + } + public static float GetSingle(this byte[] bytes, ref int offset, Endianess endianess) => BitConverter.ToSingle(bytes.Slice(ref offset, 4).To(endianess), 0); + + public static byte[] GetDouble(this byte[] bytes, ref int offset, out double value) => GetDouble(bytes, ref offset, out value, Endianess.LITTLE); + public static byte[] GetDouble(this byte[] bytes, ref int offset, out double value, Endianess endianess) + { + value = GetDouble(bytes, ref offset, endianess); + return bytes; + } + public static double GetDouble(this byte[] bytes, ref int offset, Endianess endianess) => BitConverter.ToDouble(bytes.Slice(ref offset, 8).To(endianess), 0); + public static byte[] GetBytes(this byte[] bytes,ref int offset,int length,out byte[] value) {