Skip to content

Commit

Permalink
Add IndexedReader.GetUInt64
Browse files Browse the repository at this point in the history
  • Loading branch information
drewnoakes committed Aug 1, 2021
1 parent 3b57bed commit 309c292
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions MetadataExtractor/IO/IndexedReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,38 @@ public long GetInt64(int index)
GetByte(index );
}

/// <summary>Get an unsigned 64-bit integer from the buffer.</summary>
/// <param name="index">position within the data buffer to read first byte</param>
/// <returns>the 64 bit int value, between 0x0000000000000000 and 0xFFFFFFFFFFFFFFFF</returns>
/// <exception cref="System.IO.IOException">the buffer does not contain enough bytes to service the request, or index is negative</exception>
public ulong GetUInt64(int index)
{
ValidateIndex(index, 8);
if (IsMotorolaByteOrder)
{
// Motorola - MSB first
return
(ulong)GetByte(index ) << 56 |
(ulong)GetByte(index + 1) << 48 |
(ulong)GetByte(index + 2) << 40 |
(ulong)GetByte(index + 3) << 32 |
(ulong)GetByte(index + 4) << 24 |
(ulong)GetByte(index + 5) << 16 |
(ulong)GetByte(index + 6) << 8 |
GetByte(index + 7);
}
// Intel ordering - LSB first
return
(ulong)GetByte(index + 7) << 56 |
(ulong)GetByte(index + 6) << 48 |
(ulong)GetByte(index + 5) << 40 |
(ulong)GetByte(index + 4) << 32 |
(ulong)GetByte(index + 3) << 24 |
(ulong)GetByte(index + 2) << 16 |
(ulong)GetByte(index + 1) << 8 |
GetByte(index );
}

#pragma warning restore format

/// <summary>Gets a s15.16 fixed point float from the buffer.</summary>
Expand Down

0 comments on commit 309c292

Please sign in to comment.