bit swap in byte


Author Message
ville56
Regular Member

Joined: 08/06/2022
Location: Austria
Posts: 68
Posted: 07:42pm 25 Jul 2022      

I have the need to use SPI with LSB first to talk from a Pico to a VFD display. As i didn't find a way to tell the SPI to use LSB first, i need to swap the 8 bits in every byte in code. So far i figured out 2 methods:

1) bit shifting the byte to swap and the swapped byte (AND/OR to read/set bits). Slim, but takes a lot of CPU cycles.

2) table lookup, this requires 256 bytes data space (for 8 bits) but is quite fast.

Currently i have method 1 implemented. Works but limits the responsiveness of my app (analog bargraph/level-meter). Don't like to use method 2 as i'm a "save memory space junkie" (old assembler coders disease i suppose).

Does someone know of a method which is in between my 2 solutions, meaning more cpu and memory efficient in a combination?

Many thanks for any hint ...
Regards,
Gerald (OE1HGA)