Skip to content

Instantly share code, notes, and snippets.

@nesium
Created April 24, 2010 14:00
Show Gist options
  • Save nesium/377674 to your computer and use it in GitHub Desktop.
Save nesium/377674 to your computer and use it in GitHub Desktop.
static uint64_t count = 7;

static NSString *suffixes[7] = {@"B", @"KiB", @"MiB", @"GiB", @"TiB", @"PiB", @"EiB"};
uint64_t i, c;

for (i = 1024, c = 0; i < (count << 60); i <<= 10, c++){
if (bytes < i)
return [NSString stringWithFormat:@"%0.2f%@",
(double)bytes / (double)(i >> 10), suffixes[c]];
}
return @"Big";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment