Original Post
🔒 Locked
Quick question?
Advertisement
Quote:
Original post by Asheh
i understand loByte, but err, whats with the bitshift on highbyte?
You return a byte, so you shift the high byte to the low byte. You want to check if the high byte is set, don't you?
Doesnt seem to be working too well.
From the docs it says that the most significant bit is set the key is down. So so the person cant keep hold of the key. So if the key isnt down, it must be up?
From the docs it says that the most significant bit is set the key is down. So so the person cant keep hold of the key. So if the key isnt down, it must be up?
short key_up = GetAsyncKeyState(VK_UP); if(((key_up & 0xFF00)) && prevSpaceState == false) { prevSpaceState = true; if(can_rotate()) { active_piece->Rotate(); } } else { prevSpaceState = false; }Quote:
Original post by Asheh
Doesnt seem to be working too well.
From the docs it says that the most significant bit is set the key is down. So so the person cant keep hold of the key. So if the key isnt down, it must be up?
*** Source Snippet Removed ***
Not necessarily, that flag only indicates that the key has just gone down, and there is another which will show when it has just gone up. If you want to know whether the key is up or down in-between these flags being fired, you will have to keep track of it yourself.
[edit]Now that I read your snippet entirely, I realized you are all ready tracking this ;) Sorry[/edit]
To do it more generically, where sizes can be different on different platforms, you could use this little ditty (plus it doesn't trash your var when you test):
BTW, I assume you mean most significant bit, not byte ? I noticed you were testing the most significant bit by anding a whole byte to it. Not sure, though.
#include <iostream>// returns true if most significant bit is settemplate< typename bitvar >bool test_msb( bitvar bv ) { return bv & ( 1 << ( sizeof(bv) * 8 - 1 ) );}int main() { unsigned char c = 0x80; unsigned short s = 0x8000; unsigned int i = 0x80000000; if( test_msb( c ) ) { std::cout << c << "c's MSb is set" << std::endl; } if( test_msb( s ) ) { std::cout << "s's MSb is set" << std::endl; } if( test_msb( i ) ) { std::cout << "i's MSb is set" << std::endl; } return 0;}BTW, I assume you mean most significant bit, not byte ? I noticed you were testing the most significant bit by anding a whole byte to it. Not sure, though.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement