Skip to content

Instantly share code, notes, and snippets.

@IMRANALI149
IMRANALI149 / snippet.h
Created November 25, 2024 15:36 — forked from kewitz/snippet.h
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;
};
@IMRANALI149
IMRANALI149 / snippet.h
Created November 25, 2024 15:36 — forked from kewitz/snippet.h
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;
};