Advertisement
AZJIO

ConvertFileSize

Jun 6th, 2013
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <windows.h>
  3.  
  4. unsigned long long ConvertFileSize(unsigned long long iBytes, char *i10);
  5.  
  6. /* тест функции power */
  7. int main()
  8. {
  9.     unsigned long long z;
  10.     // char i10[3] = " B";
  11.     char i10[3] = {' ', 'B', '\0'};
  12.     z = ConvertFileSize(1025, &i10);
  13.     printf("%d  -  %s\n", z, i10);
  14.     //system("pause");
  15.     return 0;
  16. }
  17.  
  18. unsigned long long ConvertFileSize(unsigned long long iBytes, char *i10)
  19. {
  20.     const unsigned long long iConst = 0.0000234375; // (1024 / 1000 - 1) / 1024
  21.     if ((iBytes >= 110154232090684)&&(iBytes <= 1125323453007766)) // TB
  22.         {iBytes = iBytes / (1099511627776 + iBytes * iConst);
  23.         iBytes = round(iBytes);
  24.         *i10 = "TB";}
  25.     else if ((iBytes >= 1098948684577)&&(iBytes <= 110154232090683)) // TB
  26.         {iBytes = iBytes *10 / (1099511627776 + iBytes * iConst);
  27.         iBytes = round(iBytes) / 10;
  28.         *i10 = "TB";}
  29.     else if ((iBytes >= 107572492277)&&(iBytes <= 1098948684576)) // GB
  30.         {iBytes = iBytes / (1073741824 + iBytes * iConst);
  31.         iBytes = round(iBytes);
  32.         *i10 = "GB";}
  33.     else if ((iBytes >= 1073192075)&&(iBytes <= 107572492276)) // GB
  34.         {iBytes = iBytes *10 / (1073741824 + iBytes * iConst);
  35.         iBytes = round(iBytes) / 10;
  36.         *i10 = "GB";}
  37.     else if ((iBytes >= 105156613)&&(iBytes <= 1073192074)) // MB
  38.         {iBytes = iBytes / (1048576 + iBytes * iConst);
  39.         iBytes = round(iBytes);
  40.         *i10 = "MB";}
  41.     else if ((iBytes >= 1048040)&&(iBytes <= 105156612)) // MB
  42.         {iBytes = iBytes *10 / (1048576 + iBytes * iConst);
  43.         iBytes = round(iBytes) / 10;
  44.         *i10 = "MB";}
  45.     else if ((iBytes >= 102693)&&(iBytes <= 1048039)) // KB
  46.         {iBytes = iBytes / (1024 + iBytes * iConst);
  47.         iBytes = round(iBytes);
  48.         *i10 = "KB";}
  49.     else if ((iBytes >= 1000)&&(iBytes <= 102692)) // KB
  50.         {iBytes = iBytes *10 / (1024 + iBytes * iConst);
  51.         iBytes = round(iBytes) / 10;
  52.         *i10 = 'K';}
  53.     return iBytes;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement