public static void Main()
long[] input = { 0, 1023, 1024000, 1024000000, 1024000000000L, 1024000000000000L, 1024000000000000000L, long.MaxValue, -1 };
for (int i = 0; i < input.Length; i++)
Console.WriteLine(HumanReadableBytes(input[i]));
private static string HumanReadableBytes(long bytes)
string result = string.Empty;
string[] suffixes = { "Bytes", "KB", "MB", "GB", "TB", "PB", "EB" };
result = "Not a valid byte size";
result = string.Format("{0:n0} {1}", bytes, suffixes[index]);
while (Math.Round(temp, 1) >= 1000)
result = string.Format("{0:n1} {1}", temp, suffixes[index]);