Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shiftR is incorrect for multiples of 8 #6

Open
crockeea opened this issue Jan 26, 2019 · 2 comments
Open

shiftR is incorrect for multiples of 8 #6

crockeea opened this issue Jan 26, 2019 · 2 comments

Comments

@crockeea
Copy link

shiftR bs i
      | i `mod` 8 == 0 =
        B.take (B.length bs) $ B.append
          (B.replicate (i `div` 8) 0)
          (B.drop (i `div` 8) bs)

should be

shiftR bs i
      | i `mod` 8 == 0 =
        B.take (B.length bs) $ B.append
          (B.replicate (i `div` 8) 0)
          (B.take(i `div` 8) bs)
@webhive
Copy link

webhive commented Aug 27, 2023

With original code

λ> B.unpack $ (B.pack [0xFF, 0, 0, 0]) `shiftR` 8
[0,0,0,0]

After your update buffer becomes shorter

λ> B.unpack $ (B.pack [0xFF, 0, 0, 0]) `shiftR` 8
[0,255]

@webhive
Copy link

webhive commented Aug 27, 2023

So finally it should become something like this

  shiftR bs i
      | i `mod` 8 == 0 =
        B.take (B.length bs) $ B.replicate (i `div` 8) 0 <> B.take (i `div` 8) bs <> B.drop (i `div` 8) bs
     ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants