c - How to make signed 64 bit integer using one signed integer and one unsigned integer on 32 bit processor -
on 32 bit processor 32 bit compiler want make 64 bit signed integer using 1 of each signed , unsigned integer. without using predefined macro or types.
32-bit compilers handle 64-bit numbers you. unlikely need this. i'll bite. on surface pretty 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 tricky/dangerous mixing signed , unsigned integers. manually constructing int requires know how processor formats them. we'll assume 2s compliment little endian.
it helpful if gave full description of requirements. example above example make_int64(0, -1) = -4294967296 make_int64(1, -1) = -4294967295.
Comments
Post a Comment