From c7d00e03c4d2fd3095e6399cb63e5d2389c910fd Mon Sep 17 00:00:00 2001 From: Martin Pittermann Date: Wed, 3 Nov 2021 21:35:02 +0100 Subject: [PATCH] fix(pio): broken `bitReverse` function (#87) pretty self-explanatory, this is another bug I found while playing around with the PIOs. https://jsfiddle.net/bwn6j75r/ Cheers! --- src/peripherals/pio.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/peripherals/pio.ts b/src/peripherals/pio.ts index 41274f4..e0e5344 100644 --- a/src/peripherals/pio.ts +++ b/src/peripherals/pio.ts @@ -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; }