- 1 year ago
Print bytes as longlong
Comment
1 / 1
To print bytes as a long long
value in C#, you can use the BitConverter.ToInt64
method to convert the byte array to a long
value, and then simply print the result. Here's an example:
csharpbyte[] bytes = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0 };
long longValue = BitConverter.ToInt64(bytes, 0);
Console.WriteLine(longValue);
In this example, we have a byte array bytes
containing 8 bytes. We use BitConverter.ToInt64(bytes, 0)
to convert the byte array starting from index 0 to a long
value. Finally, we print the longValue
to the console.
Make sure the byte array has the appropriate length (8 bytes) and is in the correct byte order (little-endian or big-endian) depending on your data source. Adjust the index (0
in the example) if needed to start the conversion from a different position in the byte array.