Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <windows.h>
- unsigned long long ConvertFileSize(unsigned long long iBytes, char *i10);
- /* тест функции power */
- int main()
- {
- unsigned long long z;
- // char i10[3] = " B";
- char i10[3] = {' ', 'B', '\0'};
- z = ConvertFileSize(1025, &i10);
- printf("%d - %s\n", z, i10);
- //system("pause");
- return 0;
- }
- unsigned long long ConvertFileSize(unsigned long long iBytes, char *i10)
- {
- const unsigned long long iConst = 0.0000234375; // (1024 / 1000 - 1) / 1024
- if ((iBytes >= 110154232090684)&&(iBytes <= 1125323453007766)) // TB
- {iBytes = iBytes / (1099511627776 + iBytes * iConst);
- iBytes = round(iBytes);
- *i10 = "TB";}
- else if ((iBytes >= 1098948684577)&&(iBytes <= 110154232090683)) // TB
- {iBytes = iBytes *10 / (1099511627776 + iBytes * iConst);
- iBytes = round(iBytes) / 10;
- *i10 = "TB";}
- else if ((iBytes >= 107572492277)&&(iBytes <= 1098948684576)) // GB
- {iBytes = iBytes / (1073741824 + iBytes * iConst);
- iBytes = round(iBytes);
- *i10 = "GB";}
- else if ((iBytes >= 1073192075)&&(iBytes <= 107572492276)) // GB
- {iBytes = iBytes *10 / (1073741824 + iBytes * iConst);
- iBytes = round(iBytes) / 10;
- *i10 = "GB";}
- else if ((iBytes >= 105156613)&&(iBytes <= 1073192074)) // MB
- {iBytes = iBytes / (1048576 + iBytes * iConst);
- iBytes = round(iBytes);
- *i10 = "MB";}
- else if ((iBytes >= 1048040)&&(iBytes <= 105156612)) // MB
- {iBytes = iBytes *10 / (1048576 + iBytes * iConst);
- iBytes = round(iBytes) / 10;
- *i10 = "MB";}
- else if ((iBytes >= 102693)&&(iBytes <= 1048039)) // KB
- {iBytes = iBytes / (1024 + iBytes * iConst);
- iBytes = round(iBytes);
- *i10 = "KB";}
- else if ((iBytes >= 1000)&&(iBytes <= 102692)) // KB
- {iBytes = iBytes *10 / (1024 + iBytes * iConst);
- iBytes = round(iBytes) / 10;
- *i10 = 'K';}
- return iBytes;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement