Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //add here onwards to h
- SIZE_T convertToMB(SIZE_T bytes);
- SIZE_T convertToKB(SIZE_T bytes);
- string convertMemoryToHumanReadable(SIZE_T bytes);
- //add here onwards to cpp
- SIZE_T convertToMB(SIZE_T bytes){
- //1MB = 1024KB = 1048576B
- return bytes / 1024 / 1024;
- }
- SIZE_T convertToKB(SIZE_T bytes){
- //1KB = 1024B
- return bytes / 1024;
- }
- string convertMemoryToHumanReadable(SIZE_T bytes){
- stringstream ss;
- if (bytes > 1048576) //MB
- ss << convertToMB(bytes) << " MB";
- else if (bytes > 1024) //KB
- ss << convertToKB(bytes) << " KB";
- else //Bytes
- ss << bytes << " B";
- return ss.str();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement