Reputation: 805
How do I take an input of 2 32 bit unsigned integers, multiply them and get the output as a 64 bit integer in C? Any help is appreciated! Thanks.
Upvotes: 5
Views: 5615
Reputation: 145829
Just convert one of the two integers to uint64_t
:
uint32_t a, b;
uint64_t c;
/* assign to a and b */
c = (uint64_t) a * b;
Upvotes: 2
Reputation: 7788
#include <stdint.h>
uint64_t mul64(uint32_t x, uint32_t y) {
return (uint64_t)x*(uint64_t)y;
}
Upvotes: 14
Reputation: 5744
Convert the two integers to 64 bit first, then do a normal multiplication and return the value.
Upvotes: 6