From e6c616826e2d62b382e769612b6dc1515f69c687 Mon Sep 17 00:00:00 2001 From: Mogeko Date: Sun, 29 Sep 2024 02:13:14 +0800 Subject: [PATCH] fix: fix an algorithm error --- src/encoder.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/encoder.ts b/src/encoder.ts index 411f6e3..632951f 100644 --- a/src/encoder.ts +++ b/src/encoder.ts @@ -15,8 +15,8 @@ function encode6bit(b: number) { function encode3bytes(b1: number, b2: number, b3: number) { return encode6bit((b1 >> 2) & 0x3f).concat( - encode6bit(((b1 & 0x3) << 4) | ((b2 >> 4) & 0x3f)), - encode6bit(((b2 & 0xf) << 2) | ((b3 >> 6) & 0x3f)), + encode6bit((((b1 & 0x3) << 4) | (b2 >> 4)) & 0x3f), + encode6bit((((b2 & 0xf) << 2) | (b3 >> 6)) & 0x3f), encode6bit(b3 & 0x3f), ); } @@ -61,13 +61,13 @@ if (import.meta.vitest) { expect(encode6bit(64)).toStrictEqual("?"); }); - it("append3bytes", () => { + it("encode3bytes", () => { expect(encode3bytes(1, 2, 3)).toStrictEqual("0G83"); expect(encode3bytes(1, 2, 0)).toStrictEqual("0G80"); expect(encode3bytes(1, 0, 0)).toStrictEqual("0G00"); }); - it("encode64", () => { + it("encode", () => { expect( encode(Buffer.from([75, 76, 74, 6, 0]).toString("binary")), ).toStrictEqual("IqnA1W00");