Can anyone tell me why y2 and y3 give different results, when y prior to shifting is negative (as in the values below)?
#include <cstdlib> #include <iostream>
using namespace std;
int main() { int iVertPos = 7; int yCaret = 7; int cyChar = 13; int y; y = (yCaret- 1- iVertPos) * cyChar; y = y << 16; int y2 = iVertPos + (HIWORD(y)) / cyChar; int y3 = iVertPos + (y >> 16) / cyChar; cout << "y: " << y << endl; cout << "y2: " << y2 << endl; cout << "y3: " << y3 << endl; cout << endl << endl; system("PAUSE");
return 0; }
Thanks
Derek
Sorted it out: dug out the answer on usenet.
Apparently HIWORD returns an unsigned word, so obviously wouldn't handle my negative value.
Casting to short does the trick:
y = iVertPos + (short(HIWORD(lParam)) / cyChar);
Log in to post a comment.
Can anyone tell me why y2 and y3 give different results, when y prior to shifting is negative (as in the values below)?
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int iVertPos = 7;
int yCaret = 7;
int cyChar = 13;
int y;
y = (yCaret- 1- iVertPos) * cyChar;
y = y << 16;
int y2 = iVertPos + (HIWORD(y)) / cyChar;
int y3 = iVertPos + (y >> 16) / cyChar;
cout << "y: " << y << endl;
cout << "y2: " << y2 << endl;
cout << "y3: " << y3 << endl;
cout << endl << endl;
system("PAUSE");
return 0;
}
Thanks
Derek
Sorted it out: dug out the answer on usenet.
Apparently HIWORD returns an unsigned word, so obviously wouldn't handle my negative value.
Casting to short does the trick:
y = iVertPos + (short(HIWORD(lParam)) / cyChar);
Derek