public static BigInteger GuidStringToBigInt(string guidString)
Guid g = new Guid(guidString);
BigInteger bigInt = new BigInteger(g.ToByteArray());
public static BigInteger GuidStringToBigIntPositive(string guidString)
Guid g = new Guid(guidString);
var guidBytes = g.ToByteArray();
var positiveGuidBytes = new byte[guidBytes.Length + 1];
Array.Copy(guidBytes, positiveGuidBytes, guidBytes.Length);
BigInteger bigInt = new BigInteger(positiveGuidBytes);
public static string BigIntToGuidString(BigInteger bigint)
byte[] bytes = new byte[16];
bigint.ToByteArray().CopyTo(bytes, 0);
return new Guid(bytes).ToString();
public static string BigIntToGuidStringPositive(BigInteger bigint)
byte[] positiveBytes = new byte[17];
bigint.ToByteArray().CopyTo(positiveBytes, 0);
byte[] bytes = new byte[16];
Array.Copy(positiveBytes, bytes, bytes.Length);
return new Guid(bytes).ToString();
public static void Main()
string guid1 = "{ffffffff-ffff-ffff-ffff-ffffffffffff}";
Console.Write("Starting Guid: ");
Console.WriteLine(guid1);
Console.Write("Converted without added byte: ");
Console.WriteLine(GuidStringToBigInt(guid1));
BigInteger bigint1 = GuidStringToBigIntPositive(guid1);
Console.Write("Converted with added byte: ");
Console.WriteLine(bigint1);
Console.Write("Starting BigInteger: ");
Console.WriteLine(bigint1);
Console.Write("Converted without added byte: ");
Console.WriteLine(BigIntToGuidString(bigint1));
Console.WriteLine(ex.Message);
Console.Write("Converted with added byte: ");
Console.WriteLine(BigIntToGuidStringPositive(bigint1));