- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
BitConverter.ToDouble() Method in C#
The BitConverter.ToDouble() method in C# is used to return a double-precision floating-point number converted from eight bytes at a specified position in a byte array.
Synchronized
The syntax is as follows −
public static double ToDouble (byte[] val, int begnIndex);
Above, val is the byte array, whereas begnIndex is the beginning position within val.
Example
Let us now see an example −
using System; public class Demo { public static void Main(){ byte[] arr = { 0, 2, 5, 10, 20, 26, 34, 42, 50, 58, 66, 74, 82, 89, 97, 107, 115}; Console.WriteLine("Byte Array = {0} ", BitConverter.ToString(arr)); for (int i = 1; i < arr.Length - 7; i = i + 8) { double values = BitConverter.ToDouble(arr, i); Console.WriteLine("
Value = "+arr[i]); Console.WriteLine("Result = "+values); } } }
Output
This will produce the following output −
Byte Array = 00-02-05-0A-14-1A-22-2A-32-3A-42-4A-52-59-61-6B-73 Value = 2 Result = 4.84667324189914E-67 Value = 58 Result = 9.57203245252997E+247
Example
Let us now see another example −
using System; public class Demo { public static void Main(){ byte[] arr = { 0, 3, 7, 10, 18, 20, 25, 26, 34}; Console.WriteLine("Byte Array = {0} ", BitConverter.ToString(arr)); for (int i = 1; i < arr.Length - 7; i = i + 8) { double values = BitConverter.ToDouble(arr, i); Console.WriteLine("
Value = "+arr[i]); Console.WriteLine("Result = "+values); } } }
Output
This will produce the following output −
Byte Array = 00-03-07-0A-12-14-19-1A-22 Value = 3 Result = 2.09001158167895E-144
Advertisements