There is some obvious stuff I feel I should understand here, but I don:t:
void main()
{
long first = 0xffffffc1;
long second = 0x92009019;
//correct
__int64 correct = (((__int64)first << 32) | 0x00000000ffffffff) & (0xffffffff00000000 | second); //output is 0xffffffc192009019;
//incorrect
__int64 wrong = (double)(((__int64)first << 32) + second); //output is 0xffffffc092009019;
}
why does the add operation affect the upper 4 bytes, and how?
(compiler is VC++ 2003)
Probably because
secondis signed, which mean that 0x92009019 is negative.EDIT: The quesiton actually contains two questions.
1) How do you join two 32 bit numbers to a 64 bit value?
Answer:
2) Is it wise to do bit operations using the floating-point type
double?Answer: No, it’s not. Please use the right tool for the job. If you want to do bit operations, use integers. If you want (almost) continuous values, use floating-point values.