How to make signed 64 bit integer using one signed integer and one unsigned integer in 32 bit cpu
1 answer
32 bit compilers will handle 64 bit numbers for you. Therefore, it is unlikely that you really need it. But I will bite. At first glance, this is a fairly simple problem.
#include <stdint.h>
static inline int64_t make_int64(uint32_t low, int32_t high) {
return (int64_t)((uint64_t)high << 32) | low;
}
static inline void split_int64(int64_t value, uint32_t *low, int32_t *high) {
*low = value & 0xFFFFFFFF;
*high = (int32_t)((uint32_t)(value >> 32));
}
But its always tricky / dangerous mixing signed and unsigned integers. Manually constructing int also requires you to know how the processor formats them. We'll assume that his 2 compliments are few in number.
It would be helpful if you could provide a complete description of your requirements. For example, the above example make_int64 (0, -1) = -4294967296, but make_int64 (1, -1) = -4294967295.
0
source to share