Skip to content

Instantly share code, notes, and snippets.

@kewitz
Created March 13, 2014 22:37
Show Gist options
  • Save kewitz/9538604 to your computer and use it in GitHub Desktop.
Save kewitz/9538604 to your computer and use it in GitHub Desktop.
Humanizing bytesize in C/C++
string hByte(unsigned int bytes){
string r;
if (bytes <= 0) r = "0 Bytes";
else if (bytes >= 1073741824) r = to_string(bytes/1073741824) + " GBytes";
else if (bytes >= 1048576) r = to_string(bytes/1048576) + " MBytes";
else if (bytes >= 1024) r = to_string(bytes/1024) + " KBytes";
return r;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment