I boot into Linux and use the u_int64_t or the unsigned long long as you mention. A bit more type casting would get the OP there I think. Or just use the routine you mentioned.
Regards,
John McCaskill
formatting link
P
Peter Ryser
Xuint32 test1=0xFFFFFFFF; Xuint32 test2=0xBBBBBBBB; unsigned long long res64;
res64 = ((unsigned long long) test1) * ((unsigned long long) test2)
- Peter
LilacSk> Hello,
P
Peter Ryser
The definitions in xbasic_types.h are compiler independent. In other words, unfortunately, not all compilers support "unsigned long long". We also found that some of them do but the result of the computation was incorrect.
GCC does support "unsigned long long" and produces the correct result.
- Peter
Sylva>> You need to type cast test1 and test2 to be 64 bits before you
their 64 bits type ...
B
Ben Jackson
C does what's called "integral promotion" when doing a math operation. Basically, if you do some math with two types, the compiler chooses a type for the intermediate results. The simplified rule is: if the operand types fit in an int, use an int, otherwise use an unsigned int. Your multiply on the first line is going to have a 32 bit result on any
32-bit-int system. That means when you shift it down 32, you'll get 0.
The only way to get the compiler to do the math in a wider type is to explicitly force one of them to be wider. That's what all the casting is about in the other replies you've gotten. If it's not working, it's a flaw of your compiler. The PPC target of GCC could do what you want just fine.
Ben Jackson AD7GD
http://www.ben.com/
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.