How to combine two 32-bit integers into one 64-bit integer?
Posted
by Bei337
on Stack Overflow
See other posts from Stack Overflow
or by Bei337
Published on 2010-05-04T20:49:28Z
Indexed on
2010/05/04
20:58 UTC
Read the original article
Hit count: 133
I have a count register, which is made up of two 32-bit unsigned integers, one for the higher 32 bits of the value (most significant word), and other for the lower 32 bits of the value (least significant word).
What is the best way in C to combine these two 32-bit unsigned integers and then display as a large number?
In specific:
leastSignificantWord = 4294967295; //2^32-1
printf("Counter: %u%u", mostSignificantWord,leastSignificantWord);
This would print fine.
When the number is incremented to 4294967296, I have it so the leastSignificantWord wipes to 0, and mostSignificantWord (0 initially) is now 1. The whole counter should now read 4294967296, but right now it just reads 10, because I'm just concatenating 1 from mostSignificantWord and 0 from leastSignificantWord.
How should I make it display 4294967296 instead of 10?
© Stack Overflow or respective owner