- 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
C# BitConverter.ToInt64() Method
The BitConverter.ToInt64() method in C# is used to return a 64-bit signed integer converted from eight bytes at a specified position in a byte array.
Syntax
The syntax is as follows −
public static long ToInt64 (byte[] val, int begnIndex);
Above, val is the byte array, whereas begnIndex is the beginning position within val.
Let us now see an example −
Example
using System; public class Demo { public static void Main() { byte[] arr = { 0, 10, 15, 20, 26, 30, 34, 42, 50}; Console.WriteLine("Byte Array = {0} ", BitConverter.ToString(arr)); for (int i = 0; i < arr.Length - 7; i = i + 8) { long res = BitConverter.ToInt64(arr, i); Console.WriteLine("
Value = "+arr[i]); Console.WriteLine("Result = "+res); } } }
Output
This will produce the following output −
Byte Array = 00-0A-0F-14-1A-1E-22-2A-32 Value = 0 Result = 3036022196155648512
Example
Let us now see another example −
using System; public class Demo { public static void Main() { byte[] arr = {0, 0, 0, 10, 20, 0, 0, 25, 30, 0, 0, 0, 35, 45, 55, 65, 75}; Console.WriteLine("Byte Array = {0} ", BitConverter.ToString(arr)); for (int i = 0; i < arr.Length - 7; i = i + 8) { long res = BitConverter.ToInt64(arr, i); Console.WriteLine("
Value = "+arr[i]); Console.WriteLine("Result = "+res); } } }
Output
This will produce the following output −
Byte Array = 00-00-00-0A-14-00-00-19-1E-00-00-00-23-2D-37-41-4B Value = 0 Result = 1801439937015316480 Value = 30 Result = 4699274364531507230
Advertisements