Skip to content

Instantly share code, notes, and snippets.

@SndrSchnklshk
SndrSchnklshk / GenerateChecksum.cs
Last active August 27, 2024 13:59
Generate a simple checksum in C#
// Generates a Checksum
// EXAMPLE: Input="Hello World!!" -> Output="5E"
public static string GenerateChecksum(string input)
{
byte[] bytes = Encoding.ASCII.GetBytes(input);
byte result = 0;
foreach (byte c in bytes)
result += c;
result &= 0xff;
return result.ToString("X2");
@SndrSchnklshk
SndrSchnklshk / CalculatePI.cs
Last active August 2, 2018 07:27
Calculate PI in C# the plain and stupid way :)
// Calculate PI
// OUTPUT (59 seconds on my old i5 laptop):
// PI = 3.14159264498239 vs 3.14159265358979
// Difference = 8.60740323460618E-09
public double CalculatePI()
{
double pi = 0;
double sum = 1;
double sqr = 0;
for (double n = 2; n < 10000000000; n++)