Skip to content

setBit changes length of bytestring #2

@clample

Description

@clample

This behaviour might be desired, but I thought I would bring it up. When setBit is called, the returned bytestring doesn't contain any of the bytes after the index.

Prelude> import qualified Data.ByteString.Base16 as B16
Prelude B16> import Data.Bits
Prelude B16 Data.Bits> import Data.Bits.ByteString
Prelude B16 Data.Bits Data.Bits.ByteString> import qualified Data.ByteString as B
Prelude B16 Data.Bits Data.Bits.ByteString B> import qualified Data.ByteString.Char8 as Char8
Prelude B16 Data.Bits Data.Bits.ByteString B Char8> let zeroes = fst . B16.decode . Char8.pack $ "0000"
Prelude B16 Data.Bits Data.Bits.ByteString B Char8> B.length zeroes
2
Prelude B16 Data.Bits Data.Bits.ByteString B Char8> let newBS = setBit zeroes 0
Prelude B16 Data.Bits Data.Bits.ByteString B Char8> B.length newBS
1
Prelude B16 Data.Bits Data.Bits.ByteString B Char8> Char8.unpack . B16.encode $ newBS 
"01"

If you try to set the first bit on a long bytestring, the returned bytestring will only have 1 byte

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions