/// <summary> /// Fills the array with eight bytes of the specified 64-bit signed integer value beginning at <paramref name="startIndex"/>. /// </summary> /// <param name="value">The number to convert.</param> /// <param name="buffer">The array of bytes to store converted value at.</param> /// <param name="startIndex">The start index where converted value is to be stored at <paramref name="buffer"/>.</param> public static void FillBytes(long value, byte[] buffer, int startIndex) { BitConverterServices.ValidateFillArguments(buffer, startIndex, 8); FillBytes((int)value, buffer, startIndex); FillBytes((int)(value >> 32), buffer, startIndex + 4); }
/// <summary> /// Fills the array with two bytes of the specified 16-bit signed integer value beginning at <paramref name="startIndex"/>. /// </summary> /// <param name="value">The number to convert.</param> /// <param name="buffer">The array of bytes to store converted value at.</param> /// <param name="startIndex">The start index where converted value is to be stored at <paramref name="buffer"/>.</param> public static void FillBytes(short value, byte[] buffer, int startIndex) { BitConverterServices.ValidateFillArguments(buffer, startIndex, 2); buffer[startIndex++] = (byte)value; buffer[startIndex] = (byte)(value >> 8); }
/// <summary> /// Fills the array with sixteen bytes of the specified decimal value beginning at <paramref name="startIndex"/>. /// </summary> /// <param name="value">The number to convert.</param> /// <param name="buffer">The array of bytes to store converted value at.</param> /// <param name="startIndex">The start index where converted value is to be stored at <paramref name="buffer"/>.</param> public static void FillBytes(decimal value, byte[] buffer, int startIndex) { BitConverterServices.ValidateFillArguments(buffer, startIndex, 16); var bits = decimal.GetBits(value); for (int i = 0; i < bits.Length; ++i) { FillBytes(bits[i], buffer, startIndex + i * sizeof(int)); } }
/// <summary> /// Fills the array with eight bytes of the specified double-precision floating point value beginning at <paramref name="startIndex"/>. /// </summary> /// <param name="value">The number to convert.</param> /// <param name="buffer">The array of bytes to store converted value at.</param> /// <param name="startIndex">The start index where converted value is to be stored at <paramref name="buffer"/>.</param> public static void FillBytes(double value, byte[] buffer, int startIndex) { BitConverterServices.ValidateFillArguments(buffer, startIndex, 8); FillBytes(BitConverter.DoubleToInt64Bits(value), buffer, startIndex); }
/// <summary> /// Fills the array with four bytes of the specified single-precision floating point value beginning at <paramref name="startIndex"/>. /// </summary> /// <param name="value">The number to convert.</param> /// <param name="buffer">The array of bytes to store converted value at.</param> /// <param name="startIndex">The start index where converted value is to be stored at <paramref name="buffer"/>.</param> public static void FillBytes(float value, byte[] buffer, int startIndex) { BitConverterServices.ValidateFillArguments(buffer, startIndex, 4); FillBytes(BitConverterEx.SingleToInt32Bits(value), buffer, startIndex); }