I don't know much about bit math, or else I wouldn't be asking this.
What is the simplest way to swap the first and last nybbles in a byte?
For example, turn
01101010 into 10100110
Thanks for the help!
By the way, if you want to know why, I have a custom pcb for 2 led matrices, but I swapped the top and bottom rows of each matrices' connections! I can't rotate it, since it is not rotationally symmetrical.
No guarantee that would compile to the most efficient nibble swap implementation. But we are using C here...where the rule is to do it the easiest way until you run into performance problems.
Whatever solution I use, I am just going to make a function (or a #define) called swap(value), so it doesn't really matter which is simplest or shortest.
but how were the bytes-with-incorrect-nybble-order originally assembled? Is it not possible to modify that code so that no extra swap need to be performed?
Yes, I messed it up so whennit should be going through the rows and columns linearly,
12345678
It goes through them as follows,
56781234
Sort of annoying, but easily solved thru software.
swap is a single cycle instruction on the atmega. there will be some additional code for moving a memory location into a register and then writing back, but that is also the case with the shifts.
so the swap version is the fastest/smallest. not c portable though, but we are in the context of arduino here, aren't we?