How to convert an array of bytes, Byte [] from small to large.
I am thinking of porting this program to Mono and wondered which approach is best suited. Any help would be greatly appreciated.
EDIT: I read from a file in both widows and mono.
Thank. Bean.
" byte[] ", , byte[]. , 2- , 4- 4 . , . , , , .
byte[]
Mono.DataConvert - , , , . ; , . MIT , , .
, , . . . , , , , - , .., .
, , , char .., . / ( , char ..)
Array.Reverse(), , ...
public static void Reverse( Array array, int index, int length )
( ) . , , . , :
using System; using System.Text; public class Program { public static void Main() { string key = "B13E745599654841172F741A662880D4"; var guid = new Guid(key); string hex = HexStringFromBytes(guid.ToByteArray()); Console.WriteLine("Original key: " + guid); Console.WriteLine(); Console.WriteLine("Big-endian version of the key: " + hex); Console.ReadLine(); } public static string HexStringFromBytes(byte[] bytes) { var sb = new StringBuilder(); foreach (byte b in bytes) { var hex = b.ToString("x2"); sb.Append(hex); } return sb.ToString(); } }
:
: B13E7455-9965-4841-172F-741A662880D4
: 55743eb165994148172f741a662880d4
: Endian to Big Endian
Do you want to change the objects in the array or the value of the bytes themselves? If only an array, then you can useArray.Reverse()
Array.Reverse()
Source: https://habr.com/ru/post/1784571/More articles:Installing gdal-config on my Linux - gdalSmall refactoring in a Java Swing application causes a significant slowdown - javaComparing list items - typesКак я могу использовать словарь-адаптер от Castle Core 2.5.2? - c#java- choosing the execution time of a block of code - javaHow to close iPad application in Objective-C? - iphoneExecute a batch file in C # - c #How to import the source code of an Android application project into Eclipse? - androidNeed help with random mines in minesweeper game - javaUsing the BasedOn property with a style defined in another dictionary - c #All Articles