Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. //add here onwards to h
  2.  
  3. SIZE_T convertToMB(SIZE_T bytes);
  4. SIZE_T convertToKB(SIZE_T bytes);
  5. string convertMemoryToHumanReadable(SIZE_T bytes);
  6.  
  7.  
  8.  
  9. //add here onwards to cpp
  10. SIZE_T convertToMB(SIZE_T bytes){
  11. //1MB = 1024KB = 1048576B
  12. return bytes / 1024 / 1024;
  13. }
  14.  
  15. SIZE_T convertToKB(SIZE_T bytes){
  16. //1KB = 1024B
  17. return bytes / 1024;
  18. }
  19.  
  20. string convertMemoryToHumanReadable(SIZE_T bytes){
  21. stringstream ss;
  22. if (bytes > 1048576) //MB
  23. ss << convertToMB(bytes) << " MB";
  24. else if (bytes > 1024) //KB
  25. ss << convertToKB(bytes) << " KB";
  26. else //Bytes
  27. ss << bytes << " B";
  28. return ss.str();
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement