Esempio n. 1
0
        /// <summary>
        /// Convert to byte array.
        /// </summary>
        /// <param name="value">The current value.</param>
        /// <param name="order">The byte order.</param>
        /// <returns>The byte array.</returns>
        public static byte[] InternalToByteArray(this ulong value, Nequeo.Custom.ByteOrder order)
        {
            var bytes = BitConverter.GetBytes(value);

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

            return(bytes);
        }
Esempio n. 2
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="ByteOrder"/> enum values, indicates 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, Nequeo.Custom.ByteOrder sourceOrder)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            return(source.Length > 1 && !sourceOrder.IsHostOrder()
                   ? source.Reverse()
                   : source);
        }
Esempio n. 3
0
 /// <summary>
 /// Convert the source byte array to the byte order.
 /// </summary>
 /// <param name="source">The current sources</param>
 /// <param name="sourceOrder">The byte order.</param>
 /// <returns>The unsigned int.</returns>
 public static ulong ToUInt64(this Byte[] source, Nequeo.Custom.ByteOrder sourceOrder)
 {
     return(BitConverter.ToUInt64(source.ToHostOrder(sourceOrder), 0));
 }