C++ mega giga
Date: 2020-05-09Last modified: 2024-11-02
Table of contents
#include <iostream>
#include <locale>
using namespace std;
// clang-format off
// 2^0 = 1 = 1000^0 (0% deviation)
// 2^10 = 1 024 ≈ 1000^1 (2.4% deviation)
// 2^20 = 1 048 576 ≈ 1000^2 (4.9% deviation)
// 2^30 = 1 073 741 824 ≈ 1000^3 (7.4% deviation)
// 2^40 = 1 099 511 627 776 ≈ 1000^4 (10.0% deviation)
// 2^50 = 1 125 899 906 842 624 ≈ 1000^5 (12.6% deviation)
// 2^60 = 1 152 921 504 606 846 976 ≈ 1000^6 (15.3% deviation)
// 2^70 = 1 180 591 620 717 411 303 424 ≈ 1000^7 (18.1% deviation)
// 2^80 = 1 208 925 819 614 629 174 706 176 ≈ 1000^8 (20.9% deviation)
// 2^90 = 1 237 940 039 285 380 274 899 124 224 ≈ 1000^9 (23.8% deviation)
// 2^100 = 1 267 650 600 228 229 401 496 703 205 376 ≈ 1000^10 (26.8% deviation)
// 2^110 = 1 298 074 214 633 706 907 132 624 082 305 024 ≈ 1000^11 (29.8% deviation)
// 2^120 = 1 329 227 995 784 915 872 903 807 060 280 344 576 ≈ 1000^12 (32.9% deviation)
// 2^130 = 1 361 129 467 683 753 853 853 498 429 727 072 845 824 ≈ 1000^13 (36.1% deviation)
// 2^140 = 1 393 796 574 908 163 946 345 982 392 040 522 594 123 776 ≈ 1000^14 (39.4% deviation)
// 2^150 = 1 427 247 692 705 959 881 058 285 969 449 495 136 382 746 624 ≈ 1000^15 (42.7% deviation)
// clang-format on
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) {
cout << "1 kB = 1 x 2^10 = " << (1 << 10) << endl;
cout << "3 MB = 3 x 2^20 = " << (3 << 20) << endl;
cout << "5 GB = 5 x 2^30 = " << (5UL << 30) << endl;
cout << "7 TB = 7 x 2^40 = " << (7UL << 40) << endl;
cout << "9 TB = 9 x 2^50 = " << (9UL << 50) << endl;
cout.imbue(locale(""));
cout << "1 kB = 1 x 2^10 = " << (1 << 10) << endl;
cout << "3 MB = 3 x 2^20 = " << (3 << 20) << endl;
cout << "5 GB = 5 x 2^30 = " << (5UL << 30) << endl;
cout << "7 TB = 7 x 2^40 = " << (7UL << 40) << endl;
cout << "9 TB = 9 x 2^50 = " << (9UL << 50) << endl;
}
## Possible output
//-- ## Possible output
```txt
1 kB = 1 x 2^10 = 1024
3 MB = 3 x 2^20 = 3145728
5 GB = 5 x 2^30 = 5368709120
7 TB = 7 x 2^40 = 7696581394432
9 TB = 9 x 2^50 = 10133099161583616
1 kB = 1 x 2^10 = 1,024
3 MB = 3 x 2^20 = 3,145,728
5 GB = 5 x 2^30 = 5,368,709,120
7 TB = 7 x 2^40 = 7,696,581,394,432
9 TB = 9 x 2^50 = 10,133,099,161,583,616
References
//-- ## References
// clang-format off