Enviado em 12/06/2024 - 22:17h
#include <cmath>
#include <iomanip>
#include <iostream>
/*
*
*http://extraconversion.com/pt/armazenamento-de-dados/mebibytes/mebibytes-para-gibibytes.html
*https://highscalability.com/how-big-is-a-petabyte-exabyte-zettabyte-or-a-yottabyte/
*/
void convertBytes(double bytes)
{
int const base = 1024;
std::string units[9] = {"bytes", "kilobytes", "megabytes", "gigabytes", "terabytes", "petabytes", "exabytes", "zettabytes", "yottabytes"};
int tam = (sizeof(units) / sizeof(units[0]));
std::cout << std::fixed << std::setprecision(0); // pega até o primeiro ponto.
std::cout << "Bits: " << (bytes * 8) << std::endl;
for (int i = 0; i < tam; i++)
{
std::cout << units[i] << ": " << bytes << std::endl;
bytes /= base;
}
}
void convertLLBytes(long long bytes)
{
//int const base = 1024;
long long const base = 1024LL;
std::string units[9] = {"bytes","kilobytes", "megabytes", "gigabytes", "terabytes", "petabytes", "exabytes", "zettabytes", "yottabytes"};
int tam = (sizeof(units) / sizeof(units[0]));
std::cout << std::fixed << std::setprecision(0); // pega até o primeiro ponto.
std::cout << "Bits: " << (bytes * 8) << std::endl;
for (int i = 0; i <= tam; i++)
{
std::cout << units[i] << ": " << bytes << std::endl;
bytes /= base;
if (bytes == 0) break;
}
}
int main()
{
//double bytes;
//std::cout << "Digite a quantidade de bytes: ";
//std::cin >> bytes;
//convertBytes(bytes);
//std::cout<<std::endl;
long long ytbytes = 1208925819614629174LL; //1 Yottabyte (1 YB)
convertLLBytes(ytbytes);
return 0;
}
Bits: -8775337516792518224
bytes: 1208925819614629174
kilobytes: 1180591620717411
megabytes: 1152921504606
gigabytes: 1125899906
terabytes: 1099511
petabytes: 1073
exabytes: 1