Skip to content

ReadInt32 with not aligned byte #10

Open

Description

@loconox

Hi,

I'm not sure but I think the method bitReader in the class Int32 is wrong.
My fix is on the masks. I think it should be :

        $hiMask = $bitmask->getMask($br->getCurrentBit(), BitMask::MASK_LO) ^ 0xFF;
        $loMask = $bitmask->getMask($br->getCurrentBit(), BitMask::MASK_HI) ^ 0xFF;

Case :

Buffer :
FF 07 00 00 00

Position : 1 (2nd byte)
Current bit : 2
Nest Byte : FF

Try to read int32.

The masks are :
hiMask : 00111111
loMask : 00000011

But should be :
hiMask : 11111100
loMask : 11000000

The result will be 1058799616 (111111000111000000000000000000) and should be 4229693440 (11111100000111000000000000000000).

Activity

  1. loconox commented on Mar 6, 2015

    @loconox
    Author

    Correction, the low mask is correct and should not be changed.

            $loMask = $bitmask->getMask($br->getCurrentBit(), BitMask::MASK_LO);
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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