Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kiminuo committed Jan 9, 2024
1 parent 5708d91 commit 0374d0b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion NBitcoin/UInt256.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

using NBitcoin.DataEncoders;
using System;
#if HAS_SPAN
using System.Buffers.Binary;
#endif
using System.Linq;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -162,6 +163,10 @@ public override string ToString()
}

#if HAS_SPAN

/// <summary>
/// Returns HEX string representation.
/// </summary>
/// <remarks>The method allocates a new 64 char array.</remarks>
public Span<char> ToSpanString()
{
Expand All @@ -171,6 +176,9 @@ public Span<char> ToSpanString()
return result;
}

/// <summary>
/// Returns HEX string representation.
/// </summary>
/// <remarks>The method does not allocate.</remarks>
public void ToSpanString(Span<char> destination)
{
Expand All @@ -193,6 +201,7 @@ public void ToSpanString(Span<char> destination)

Span<byte> bytes = MemoryMarshal.Cast<ulong, byte>(ulongs);

// Reverses order of bytes of pn0, pn1, pn2, and pn3 are set in a little endian manner.
for (int i = 31, j = 0; i >= 0; i--, j += 2)
{
HexEncoder.ToCharsBuffer(bytes[i], destination, startingIndex: j);
Expand Down

0 comments on commit 0374d0b

Please sign in to comment.