File tree Expand file tree Collapse file tree 1 file changed +16
-13
lines changed
Expand file tree Collapse file tree 1 file changed +16
-13
lines changed Original file line number Diff line number Diff line change 11
22using NBitcoin . DataEncoders ;
33using System ;
4+ using System . Buffers . Binary ;
45using System . Linq ;
56using System . Runtime . InteropServices ;
67
@@ -174,25 +175,27 @@ public Span<char> ToSpanString()
174175 public void ToSpanString ( Span < char > destination )
175176 {
176177 Span < ulong > ulongs = stackalloc ulong [ 4 ] ;
177- ulongs [ 0 ] = pn0 ;
178- ulongs [ 1 ] = pn1 ;
179- ulongs [ 2 ] = pn2 ;
180- ulongs [ 3 ] = pn3 ;
181- Span < byte > bytes = MemoryMarshal . Cast < ulong , byte > ( ulongs ) ;
182178
183179 if ( BitConverter . IsLittleEndian )
184180 {
185- for ( int i = 31 , j = 0 ; i >= 0 ; i -- , j += 2 )
186- {
187- HexEncoder . ToCharsBuffer ( bytes [ i ] , destination , startingIndex : j ) ;
188- }
181+ ulongs [ 0 ] = pn0 ;
182+ ulongs [ 1 ] = pn1 ;
183+ ulongs [ 2 ] = pn2 ;
184+ ulongs [ 3 ] = pn3 ;
189185 }
190186 else
191187 {
192- for ( int i = 0 ; i < 32 ; i ++ )
193- {
194- HexEncoder . ToCharsBuffer ( bytes [ i ] , destination , startingIndex : i ) ;
195- }
188+ ulongs [ 0 ] = BinaryPrimitives . ReverseEndianness ( pn0 ) ;
189+ ulongs [ 1 ] = BinaryPrimitives . ReverseEndianness ( pn1 ) ;
190+ ulongs [ 2 ] = BinaryPrimitives . ReverseEndianness ( pn2 ) ;
191+ ulongs [ 3 ] = BinaryPrimitives . ReverseEndianness ( pn3 ) ;
192+ }
193+
194+ Span < byte > bytes = MemoryMarshal . Cast < ulong , byte > ( ulongs ) ;
195+
196+ for ( int i = 31 , j = 0 ; i >= 0 ; i -- , j += 2 )
197+ {
198+ HexEncoder . ToCharsBuffer ( bytes [ i ] , destination , startingIndex : j ) ;
196199 }
197200 }
198201#endif
You can’t perform that action at this time.
0 commit comments