System.BitConverter.ToSingle C# (CSharp) Метод

ToSingle() публичный статический метод

public static ToSingle ( byte value, int startIndex ) : float
value byte
startIndex int
Результат float
        unsafe public static float ToSingle (byte[]value, int startIndex)
        {
            int val = ToInt32(value, startIndex);
            return *(float*)&val;
        }
      

Usage Example

Пример #1
0
        public override async Task Decode(EbmlParser parser, bool forceDecode = false)
        {
            if (Decoded && !forceDecode)
            {
                return;
            }
            if (parser == null)
            {
                throw new ArgumentNullException(nameof(parser));
            }
            if (parser.DataAccessor == null)
            {
                throw new InvalidOperationException(
                          ExceptionsResourceManager.ResourceManager.GetString("InvalidDecodeState", CultureInfo.CurrentCulture));
            }

            switch (DataSize.DataSize)
            {
            case 0:
                Value = 0;
                break;

            case 4:
                var floatBuffer = new byte[4];
                parser.DataAccessor.Position = DataPosition;
                await parser.DataAccessor.ReadAsync(floatBuffer, 0, 4).ConfigureAwait(false);

                Utility.ConvertEndiannes(floatBuffer);
                Value = BitConverter.ToSingle(floatBuffer);
                break;

            case 8:
                var doubleBuffer = new byte[8];
                parser.DataAccessor.Position = DataPosition;
                await parser.DataAccessor.ReadAsync(doubleBuffer, 0, 8).ConfigureAwait(false);

                Utility.ConvertEndiannes(doubleBuffer);
                Value = BitConverter.ToDouble(doubleBuffer);
                break;

            default:
                throw new DecodeException("Can not decode a decimal number that is not either 0, 4 or 8 bytes long");
            }

            Decoded = true;
        }
All Usage Examples Of System.BitConverter::ToSingle