Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ FormatBigIntegerToHex()

static string System.Numerics.BigNumber.FormatBigIntegerToHex ( bool targetSpan,
BigInteger value,
char format,
int digits,
NumberFormatInfo info,
Span< char > destination,
out int charsWritten,
out bool spanSuccess )
inlinestaticprivate

Definition at line 362 of file BigNumber.cs.

363 {
364 byte[] array = null;
365 Span<byte> destination2 = stackalloc byte[64];
366 if (!value.TryWriteOrCountBytes(destination2, out var bytesWritten))
367 {
368 destination2 = (array = ArrayPool<byte>.Shared.Rent(bytesWritten));
369 bool flag = value.TryWriteBytes(destination2, out bytesWritten);
370 }
371 destination2 = destination2.Slice(0, bytesWritten);
372 Span<char> initialBuffer = stackalloc char[128];
373 System.Text.ValueStringBuilder valueStringBuilder = new System.Text.ValueStringBuilder(initialBuffer);
374 int num = destination2.Length - 1;
375 if (num > -1)
376 {
377 bool flag2 = false;
378 byte b = destination2[num];
379 if (b > 247)
380 {
381 b -= 240;
382 flag2 = true;
383 }
384 if (b < 8 || flag2)
385 {
386 valueStringBuilder.Append((b < 10) ? ((char)(b + 48)) : ((format == 'X') ? ((char)((b & 0xF) - 10 + 65)) : ((char)((b & 0xF) - 10 + 97))));
387 num--;
388 }
389 }
390 if (num > -1)
391 {
392 Span<char> span = valueStringBuilder.AppendSpan((num + 1) * 2);
393 int num2 = 0;
394 string text = ((format == 'x') ? "0123456789abcdef" : "0123456789ABCDEF");
395 while (num > -1)
396 {
397 byte b2 = destination2[num--];
398 span[num2++] = text[b2 >> 4];
399 span[num2++] = text[b2 & 0xF];
400 }
401 }
402 if (digits > valueStringBuilder.Length)
403 {
404 valueStringBuilder.Insert(0, (value._sign >= 0) ? '0' : ((format == 'x') ? 'f' : 'F'), digits - valueStringBuilder.Length);
405 }
406 if (array != null)
407 {
409 }
410 if (targetSpan)
411 {
412 spanSuccess = valueStringBuilder.TryCopyTo(destination, out charsWritten);
413 return null;
414 }
415 charsWritten = 0;
416 spanSuccess = false;
417 return valueStringBuilder.ToString();
418 }
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
void Insert(int index, string s)
bool TryCopyTo(Span< char > destination, out int charsWritten)
Span< char > AppendSpan(int length)

References System.Text.ValueStringBuilder.Append(), System.Text.ValueStringBuilder.AppendSpan(), System.array, System.destination, System.format, System.Text.ValueStringBuilder.Insert(), System.Text.ValueStringBuilder.Length, System.Buffers.ArrayPool< T >.Shared, System.Span< T >.Slice(), System.text, System.Text.ValueStringBuilder.ToString(), System.Text.ValueStringBuilder.TryCopyTo(), and System.value.

Referenced by System.Numerics.BigNumber.FormatBigInteger().