fork download
  1. // Example of the BitConverter.ToInt64 method.
  2. using System;
  3.  
  4. class BytesToInt64Demo
  5. {
  6. const string formatter = "{0,5}{1,27}{2,24}";
  7.  
  8. // Convert eight byte array elements to a long and display it.
  9. public static void BAToInt64( byte[ ] bytes, int index )
  10. {
  11. long value = BitConverter.ToInt64( bytes, index );
  12.  
  13. Console.WriteLine( formatter, index,
  14. BitConverter.ToString( bytes, index, 8 ), value );
  15. }
  16.  
  17. // Display a byte array, using multiple lines if necessary.
  18. public static void WriteMultiLineByteArray( byte[ ] bytes )
  19. {
  20. const int rowSize = 20;
  21. int iter;
  22.  
  23. Console.WriteLine( "initial byte array" );
  24. Console.WriteLine( "------------------" );
  25.  
  26. for( iter = 0; iter < bytes.Length - rowSize; iter += rowSize )
  27. {
  28. Console.Write(
  29. BitConverter.ToString( bytes, iter, rowSize ) );
  30. Console.WriteLine( "-" );
  31. }
  32.  
  33. Console.WriteLine( BitConverter.ToString( bytes, iter ) );
  34. Console.WriteLine( );
  35. }
  36.  
  37. public static void Main( )
  38. {
  39. byte[ ] byteArray = {
  40. 226, 220, 0, 0, 0, 0, 0, 0};
  41.  
  42. Console.WriteLine(
  43. "This example of the BitConverter.ToInt64( byte[ ], " +
  44. "int ) \nmethod generates the following output. It " +
  45. "converts elements \nof a byte array to long values.\r\n" );
  46.  
  47. WriteMultiLineByteArray( byteArray );
  48.  
  49. Console.WriteLine( formatter, "index", "array elements", "long" );
  50. Console.WriteLine( formatter, "-----", "--------------", "----" );
  51.  
  52. // Convert byte array elements to long values.
  53. BAToInt64( byteArray, 0 );
  54. }
  55. }
  56.  
  57. /*
  58. This example of the BitConverter.ToInt64( byte[ ], int )
  59. method generates the following output. It converts elements
  60. of a byte array to long values.
  61.  
  62. initial byte array
  63. ------------------
  64. 00-36-65-C4-FF-FF-FF-FF-00-00-00-00-00-00-00-00-80-00-CA-9A-
  65. 3B-00-00-00-00-01-00-00-00-00-FF-FF-FF-FF-01-00-00-FF-FF-FF-
  66. FF-FF-FF-FF-7F-56-55-55-55-55-55-FF-FF-AA-AA-AA-AA-AA-AA-00-
  67. 00-64-A7-B3-B6-E0-0D-00-00-9C-58-4C-49-1F-F2
  68.  
  69. index array elements long
  70. ----- -------------- ----
  71.   8 00-00-00-00-00-00-00-00 0
  72.   5 FF-FF-FF-00-00-00-00-00 16777215
  73.   34 01-00-00-FF-FF-FF-FF-FF -16777215
  74.   17 00-CA-9A-3B-00-00-00-00 1000000000
  75.   0 00-36-65-C4-FF-FF-FF-FF -1000000000
  76.   21 00-00-00-00-01-00-00-00 4294967296
  77.   26 00-00-00-00-FF-FF-FF-FF -4294967296
  78.   53 AA-AA-AA-AA-AA-AA-00-00 187649984473770
  79.   45 56-55-55-55-55-55-FF-FF -187649984473770
  80.   59 00-00-64-A7-B3-B6-E0-0D 1000000000000000000
  81.   67 00-00-9C-58-4C-49-1F-F2 -1000000000000000000
  82.   37 FF-FF-FF-FF-FF-FF-FF-7F 9223372036854775807
  83.   9 00-00-00-00-00-00-00-80 -9223372036854775808
  84. */
Success #stdin #stdout 0.02s 24612KB
stdin
Standard input is empty
stdout
This example of the BitConverter.ToInt64( byte[ ], int ) 
method generates the following output. It converts elements 
of a byte array to long values.

initial byte array
------------------
E2-DC-00-00-00-00-00-00

index             array elements                    long
-----             --------------                    ----
    0    E2-DC-00-00-00-00-00-00                   56546