diff --git a/lodepng.cpp b/lodepng.cpp index fcad93e7..8c78758f 100644 --- a/lodepng.cpp +++ b/lodepng.cpp @@ -2385,9 +2385,10 @@ static unsigned readBitsFromReversedStream(size_t* bitpointer, const unsigned ch { unsigned result = 0; size_t i; - for(i = nbits - 1; i < nbits; --i) + for(i = 0 ; i < nbits; ++i) { - result += (unsigned)readBitFromReversedStream(bitpointer, bitstream) << i; + result <<= 1; + result |= (unsigned)readBitFromReversedStream(bitpointer, bitstream); } return result; }