Skip to content

Instantly share code, notes, and snippets.

@IMRANALI149
Forked from kewitz/snippet.h
Created November 25, 2024 15:36
Show Gist options
  • Save IMRANALI149/07b6567cd0790ba92963ba822dabb3c2 to your computer and use it in GitHub Desktop.
Save IMRANALI149/07b6567cd0790ba92963ba822dabb3c2 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