mirror of
https://github.com/mm201/pkmn-classic-framework.git
synced 2026-08-03 08:29:58 -05:00
39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
namespace PokeFoundations.GTS
|
|
{
|
|
public static class Common
|
|
{
|
|
public static string ToHexStringUpper(this byte[] bytes)
|
|
{
|
|
// http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa/14333437#14333437
|
|
char[] c = new char[bytes.Length * 2];
|
|
int b;
|
|
for (int i = 0; i < bytes.Length; i++)
|
|
{
|
|
b = bytes[i] >> 4;
|
|
c[i * 2] = (char)(55 + b + (((b - 10) >> 31) & -7));
|
|
b = bytes[i] & 0xF;
|
|
c[i * 2 + 1] = (char)(55 + b + (((b - 10) >> 31) & -7));
|
|
}
|
|
return new string(c);
|
|
}
|
|
|
|
public static string ToHexStringLower(this byte[] bytes)
|
|
{
|
|
char[] c = new char[bytes.Length * 2];
|
|
int b;
|
|
for (int i = 0; i < bytes.Length; i++)
|
|
{
|
|
b = bytes[i] >> 4;
|
|
c[i * 2] = (char)(87 + b + (((b - 10) >> 31) & -39));
|
|
b = bytes[i] & 0xF;
|
|
c[i * 2 + 1] = (char)(87 + b + (((b - 10) >> 31) & -39));
|
|
}
|
|
return new string(c);
|
|
}
|
|
}
|
|
} |