-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
30 lines (24 loc) · 860 Bytes
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <iomanip> // for std::hex
# include <cstdint>
void print_uint128(__uint128_t value) {
if (value == 0) {
std::cout << "0";
return;
}
// Split the 128-bit value into two 64-bit parts
uint64_t high = value >> 64; // The higher 64 bits
uint64_t low = value & 0xFFFFFFFFFFFFFFFFULL; // The lower 64 bits
if (high != 0) {
std::cout << std::hex << high << std::setw(16) << std::setfill('0') << low << std::dec; // Print both high and low in hex
} else {
std::cout << low; // If high is 0, print just the low part
}
}
int main() {
__uint128_t result = static_cast<__uint128_t>(1) << 127; // This is 2^128
std::cout << "2^128 is: ";
print_uint128(result); // Call our function to print the 128-bit value
std::cout << std::endl;
return 0;
}