Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HexConverter.cs
Go to the documentation of this file.
2
3namespace System;
4
5internal static class HexConverter
6{
7 public enum Casing : uint
8 {
9 Upper = 0u,
10 Lower = 8224u
11 }
12
13 public static ReadOnlySpan<byte> CharToHexLookup => new byte[256]
14 {
15 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
16 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
17 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
18 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
19 255, 255, 255, 255, 255, 255, 255, 255, 0, 1,
20 2, 3, 4, 5, 6, 7, 8, 9, 255, 255,
21 255, 255, 255, 255, 255, 10, 11, 12, 13, 14,
22 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
23 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
24 255, 255, 255, 255, 255, 255, 255, 10, 11, 12,
25 13, 14, 15, 255, 255, 255, 255, 255, 255, 255,
26 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
27 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
28 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
29 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
30 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
31 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
32 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
33 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
34 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
35 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
36 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
37 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
38 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
39 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
40 255, 255, 255, 255, 255, 255
41 };
42
43 [MethodImpl(MethodImplOptions.AggressiveInlining)]
44 public static void ToCharsBuffer(byte value, Span<char> buffer, int startingIndex = 0, Casing casing = Casing.Upper)
45 {
46 uint num = (uint)(((value & 0xF0) << 4) + (value & 0xF) - 35209);
47 uint num2 = ((((0 - num) & 0x7070) >> 4) + num + 47545) | (uint)casing;
48 buffer[startingIndex + 1] = (char)(num2 & 0xFFu);
49 buffer[startingIndex] = (char)(num2 >> 8);
50 }
51
52 [MethodImpl(MethodImplOptions.AggressiveInlining)]
53 public static int FromChar(int c)
54 {
55 if (c < CharToHexLookup.Length)
56 {
57 return CharToHexLookup[c];
58 }
59 return 255;
60 }
61
62 [MethodImpl(MethodImplOptions.AggressiveInlining)]
63 public static bool IsHexChar(int c)
64 {
65 _ = IntPtr.Size;
66 ulong num = (uint)(c - 48);
67 ulong num2 = (ulong)(-17875860044349952L << (int)num);
68 ulong num3 = num - 64;
69 if ((long)(num2 & num3) >= 0L)
70 {
71 return false;
72 }
73 return true;
74 }
75}
static void ToCharsBuffer(byte value, Span< char > buffer, int startingIndex=0, Casing casing=Casing.Upper)
static ReadOnlySpan< byte > CharToHexLookup
static bool IsHexChar(int c)
static int FromChar(int c)
static int Size
Definition IntPtr.cs:21