How to read a 16-byte unsigned integer correctly with BinaryReader

I need to parse a binary stream in .NET to convert an unsigned integer of 16 bytes. I would like to use the BinaryReader.ReadUIntXX () functions, but there is no BinaryReader.ReadUInt128 () function. I assume that I will have to collapse my own function using the ReadByte function and build an array, but I do not know if this is the most efficient method? Thank!

+3
source share
3 answers

I would like to take a loan for this, but one quick search on the net and alt:

http://msdn.microsoft.com/en-us/library/bb384066.aspx

Here is an example code (which is on the same page)

byte[] bytes = { 0, 0, 0, 25 };

// If the system architecture is little-endian (that is, little end first),
// reverse the byte array.
if (BitConverter.IsLittleEndian)
    Array.Reverse(bytes);

int i = BitConverter.ToInt32(bytes, 0);
Console.WriteLine("int: {0}", i);
// Output: int: 25

, , - big-endian little-endian. , , ( - ). ( 1 0 ), , . - -.. .. . 1 () : 10000000 00000001 (. ). , big-endian - , , litte -endian - . (. http://en.wikipedia.org/wiki/Endianness - , ....) ?

, .... , ?:) ?

+2

, 0xA3, SLaks , . BinaryReader.ReadUInt128() .NET, , , . 0xA3, .NET 4.0 BigInt. . !

+1

a guid 16 .

Guid guid = Guid (byteArray);

Guid. , BigInteger .net . bytearray BigInteger.

-1

Source: https://habr.com/ru/post/1749225/


All Articles