![]() |
Better bitwise conversion
Hello,
I am working on a program to control an arduino from a ds, and I have this code that converts all of the button input bools to a byte. Code:
//pack buttons into a byteHow can i do this more elegantly? |
Re: Better bitwise conversion
Is there a reason why you are translating one bit position to another? It looks like keysHeld() is already returning a bit per key. Can't you just do the following?
Code:
amount = keysHeld();If you want to isolate one bit from all the set bits returned by keysHeld(), you can do this: Code:
int rawBits = keysHeld();Code:
int rawBits = keysHeld(); |
Re: Better bitwise conversion
its for a ds interface to an arduino robot my team is working on
|
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(); |
Re: Better bitwise conversion
Quote:
Code:
packedKeys = keys; |
Re: Better bitwise conversion
keys stores them differently, according to this:
Code:
typedef enum KEYPAD_BITS { |
| All times are GMT -5. The time now is 13:06. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi