C++ long long manipulation
- by Krakkos
Given 2 32bit ints iMSB and iLSB
int iMSB = 12345678; // Most Significant Bits of file size in Bytes
int iLSB = 87654321; // Least Significant Bits of file size in Bytes
the long long form would be...
// Always positive so use 31 bts
long long full_size = ((long long)iMSB << 31);
full_size += (long long)(iLSB);
Now..
I don't need that much precision (that exact number of bytes), so, how can I convert the file size to MiBytes to 3 decimal places and convert to a string...
tried this...
long double file_size_megs = file_size_bytes / (1024 * 1024);
char strNumber[20];
sprintf(strNumber, "%ld", file_size_megs);
... but dosen't seem to work.
i.e. 1234567899878Bytes = 1177375.698MiB ??