In this line: secondsLived = seconds*minutes*hours*days*years; You are multiplying a number of ints together and then you assign the result to the uint_64. The computation on ints overflows. Cast at least one of the values to uint_64 before multiplying them together, so that the computation is done on uint_64 values:...
Why your solution doesn't work has already been pointed out by others. But there hasn't been a good alternative suggested yet. Try this for C++03 strtoull usage instead: #include <string> #include <cstdlib> int main() { std::string str = "1234"; // Using NULL for second parameter makes the call easier, //...
offset / 1000000 produces a value of 1.8446744073709551615 × 10^13 which is too large for tv_sec which is of type int32. The max value that can be stored in an int32 is 2.147483647 × 10^9. You're overflowing the integer you're storing the result in, and it is wrapping around and...
You are correct, the value is being truncated to 32 bits. It's easiest to verify by looking at the two values in hex: 1422028920000 = 0x14B178754C0 394745024 = 0x178754C0 So clearly you're getting the least significant 32 bits. To figure out why: are you declaring function() properly with a prototype?...
the (1 << i) in your 64 bit code might be using a regular 32-bit int for the 1. (default word size) So the 1 is shifted out completely. I don't understand how this produces the output you supplied though :) Use 1ull for the constant (unsigned long long)...
If you want to write a binary number you need to use the 0b prefix. std::uint64_t a = 0b0000000000000000000000000000000000000000000000001111111100000000; std::bitset<64> b(a); Your example fixed and working live...
Your problem is the different int types you're using. First let's check the writePosition method. You use an Int8 as parameter. So you need to make sure that you also call the method with a Int8 as parameter. To make sure you are using an Int8 you can cast it:...