Beispiel #1
0
        /// <summary>
        /// Converts the order of the specified array of <see cref="byte"/> to the host byte order.
        /// </summary>
        /// <returns>
        /// An array of <see cref="byte"/> converted from <paramref name="source"/>.
        /// </returns>
        /// <param name="source">
        /// An array of <see cref="byte"/> to convert.
        /// </param>
        /// <param name="sourceOrder">
        /// One of the <see cref="Endianness"/> enum values, specifies the byte order of
        /// <paramref name="source"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="source"/> is <see langword="null"/>.
        /// </exception>
        public static byte[] ToHostOrder(this byte[] source, Endianness sourceOrder)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(source.Length > 1 && !sourceOrder.IsHostOrder() ? source.Reverse().ToArray() : source);
        }
Beispiel #2
0
        internal static byte[] InternalToByteArray(this ulong value, Endianness order)
        {
            var bytes = BitConverter.GetBytes(value);

            if (!order.IsHostOrder())
            {
                Array.Reverse(bytes);
            }

            return(bytes);
        }