Skip to content

Commit

Permalink
fix(pio): broken bitReverse function (#87)
Browse files Browse the repository at this point in the history
pretty self-explanatory, this is another bug I found while playing around with the PIOs.

https://jsfiddle.net/bwn6j75r/

Cheers!
  • Loading branch information
martin2250 authored Nov 3, 2021
1 parent 833fea2 commit c7d00e0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/peripherals/pio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ export enum WaitType {
}

function bitReverse(x: number) {
x = ((x & 0x55555555) << 1) | ((x & 0xaaaaaaaa) >> 1);
x = ((x & 0x33333333) << 2) | ((x & 0xcccccccc) >> 2);
x = ((x & 0x0f0f0f0f) << 4) | ((x & 0xf0f0f0f0) >> 4);
x = ((x & 0x00ff00ff) << 8) | ((x & 0xff00ff00) >> 8);
x = ((x & 0x0000ffff) << 16) | ((x & 0xffff0000) >> 16);
x = ((x & 0x55555555) << 1) | ((x & 0xaaaaaaaa) >>> 1);
x = ((x & 0x33333333) << 2) | ((x & 0xcccccccc) >>> 2);
x = ((x & 0x0f0f0f0f) << 4) | ((x & 0xf0f0f0f0) >>> 4);
x = ((x & 0x00ff00ff) << 8) | ((x & 0xff00ff00) >>> 8);
x = ((x & 0x0000ffff) << 16) | ((x & 0xffff0000) >>> 16);
return x >>> 0;
}

Expand Down

0 comments on commit c7d00e0

Please sign in to comment.