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

◆ HexNumberToBigInteger()

static bool System.Numerics.BigNumber.HexNumberToBigInteger ( ref BigNumberBuffer number,
out BigInteger result )
inlinestaticprivate

Definition at line 98 of file BigNumber.cs.

99 {
100 if (number.digits == null || number.digits.Length == 0)
101 {
102 result = default(BigInteger);
103 return false;
104 }
105 int a = number.digits.Length - 1;
106 int result2;
107 int num = Math.DivRem(a, 8, out result2);
108 int num2;
109 if (result2 == 0)
110 {
111 num2 = 0;
112 }
113 else
114 {
115 num++;
116 num2 = 8 - result2;
117 }
118 bool flag = System.HexConverter.FromChar(number.digits[0]) >= 8;
119 uint num3 = ((flag && num2 > 0) ? uint.MaxValue : 0u);
120 int[] array = null;
121 Span<uint> span = ((num > 64) ? MemoryMarshal.Cast<int, uint>((array = ArrayPool<int>.Shared.Rent(num)).AsSpan(0, num)) : stackalloc uint[num]);
122 Span<uint> span2 = span;
123 int num4 = num - 1;
124 try
125 {
126 StringBuilder.ChunkEnumerator enumerator = number.digits.GetChunks().GetEnumerator();
127 while (enumerator.MoveNext())
128 {
129 ReadOnlySpan<char> span3 = enumerator.Current.Span;
130 for (int i = 0; i < span3.Length; i++)
131 {
132 char c = span3[i];
133 if (c == '\0')
134 {
135 break;
136 }
137 int num5 = System.HexConverter.FromChar(c);
138 num3 = (num3 << 4) | (uint)num5;
139 num2++;
140 if (num2 == 8)
141 {
142 span2[num4] = num3;
143 num4--;
144 num3 = 0u;
145 num2 = 0;
146 }
147 }
148 }
149 span2 = span2.TrimEnd(0u);
150 int num6;
151 uint[] array2;
152 if (span2.IsEmpty)
153 {
154 num6 = 0;
155 array2 = null;
156 }
157 else if (span2.Length == 1)
158 {
159 num6 = (int)span2[0];
160 array2 = null;
161 if ((!flag && num6 < 0) || num6 == int.MinValue)
162 {
163 array2 = new uint[1] { (uint)num6 };
164 num6 = ((!flag) ? 1 : (-1));
165 }
166 }
167 else
168 {
169 num6 = ((!flag) ? 1 : (-1));
170 array2 = span2.ToArray();
171 if (flag)
172 {
173 NumericsHelpers.DangerousMakeTwosComplement(array2);
174 }
175 }
176 result = new BigInteger(num6, array2);
177 return true;
178 }
179 finally
180 {
181 if (array != null)
182 {
184 }
185 }
186 }
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
static int FromChar(int c)
unsafe ReadOnlySpan< T > Span

References System.array, System.Text.StringBuilder.ChunkEnumerator.Current, System.Numerics.NumericsHelpers.DangerousMakeTwosComplement(), System.Math.DivRem(), System.HexConverter.FromChar(), System.Text.StringBuilder.ChunkEnumerator.GetEnumerator(), System.Span< T >.IsEmpty, System.ReadOnlySpan< T >.Length, System.Span< T >.Length, System.Text.StringBuilder.ChunkEnumerator.MoveNext(), System.Buffers.ArrayPool< T >.Shared, System.ReadOnlyMemory< T >.Span, and System.Span< T >.ToArray().

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