|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Better bitwise conversion
Well one way you could do it is with a for loop, but that would only really be efficient if the bit masks are consecutive. I only know Java, so I might get the C++ syntax wrong, but here is what it might look like:
Code:
int keys = keysHeld();
byte packedKeys = 0;
for (int i = 0; i < 8; i++) {
if (keys & (1 << i)) packedKeys |= 1 << i;
}
|
|
#2
|
||||
|
||||
|
Re: Better bitwise conversion
Quote:
Code:
packedKeys = keys; |
|
#3
|
||||
|
||||
|
Re: Better bitwise conversion
keys stores them differently, according to this:
Code:
typedef enum KEYPAD_BITS {
KEY_A = BIT(0), //!< Keypad A button.
KEY_B = BIT(1), //!< Keypad B button.
KEY_SELECT = BIT(2), //!< Keypad SELECT button.
KEY_START = BIT(3), //!< Keypad START button.
KEY_RIGHT = BIT(4), //!< Keypad RIGHT button.
KEY_LEFT = BIT(5), //!< Keypad LEFT button.
KEY_UP = BIT(6), //!< Keypad UP button.
KEY_DOWN = BIT(7), //!< Keypad DOWN button.
KEY_R = BIT(8), //!< Right shoulder button.
KEY_L = BIT(9), //!< Left shoulder button.
KEY_X = BIT(10), //!< Keypad X button.
KEY_Y = BIT(11), //!< Keypad Y button.
KEY_TOUCH = BIT(12), //!< Touchscreen pendown.
KEY_LID = BIT(13) //!< Lid state.
} KEYPAD_BITS;
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|