Re: need a 32 bit decimal number by Cezary
Cezary
Sat Oct 11 11:59:21 CDT 2008
Hello,
>> The top bit in a 64-bit integer is not set in that number, but the top bit
>> in a 32-bit number is. The problem is that the math is all done using
>> ints - casting the constant multipliers to unsigned int or to __int64 will
>> yield the correct answer.
> Thanks, that worked.
Simply add ,,U'' postfix to a constant:
__int64 dec_val = 0xEA * 0x01000000U;
Arguments of binary expressions are converted to the most ,,capacious''
type, but at least to int. Unsigned integral types are considered to be
wider then signed counterparts. Then we have: (signed => unsigned) *
unsigned, which produces unsigned int. Otherwise we will have int * int,
which produces int regardless of overflow. In the first case we have
unsigned to __int64 conversion by assignment operator and zero extended
MSB. In the second case we have signed (negative with MSB set) to
__int64 conversion and sign extended MSB which, in effect, produces
negative ,,dec_val''.
-- best regards
Cezary Noweta