Page 1 of 1

MSB-LSB Bit swop not working with ESP32 Compiler

Posted: Thu Oct 30, 2025 8:20 pm
by dvcam99
Hello Flow Code Community,

may some one could help me please. I´ll try to use the follwing MSB-LSB Bit swop with ESP32:

DATACRC = (DATACRC >> 7) & 1 | (DATACRC >> 5) & 2 | (DATACRC >> 3) & 4 | (DATACRC >> 1) & 8 | (DATACRC << 1) & 0x10 | (DATACRC << 3) & 0x20 | (DATACRC << 5) & 0x40 | (DATACRC << 7) & 0x80

Unfortunately with this calculation I can not compile to ESP32. With my PIC 18Fxxxx Controler I never had a compile problem with this calculation.

May somebody can teach me how to modify.

BR
Dirk

Re: MSB-LSB Bit swop not working with ESP32 Compiler

Posted: Thu Oct 30, 2025 8:30 pm
by dvcam99
OK found the problem by my self. Missing brackets were the problem. Here ist the correct version:

DATACRC = ((DATACRC >> 7) & 0x01) |
((DATACRC >> 5) & 0x02) |
((DATACRC >> 3) & 0x04) |
((DATACRC >> 1) & 0x08) |
((DATACRC << 1) & 0x10) |
((DATACRC << 3) & 0x20) |
((DATACRC << 5) & 0x40) |
((DATACRC << 7) & 0x80);

Re: MSB-LSB Bit swop not working with ESP32 Compiler

Posted: Thu Oct 30, 2025 11:04 pm
by mnfisher
There are some interesting algorithms:

Depending on how often you need to reverse the bits of a byte 0 - the quickest technique is probably a lookup table rev[256]

Where :
rev[0] = 0
rev[1] = 0x80
rev[2] = 0x40
etc

Then to reverse a byte rev_byte = rev[byte].

See also Hacker's Delight (Henry S Warren Jr) :-)

Martin