MabeEnum\EnumSet::setBinaryBitsetLe PHP Method

setBinaryBitsetLe() public method

NOTE: It resets the current position of the iterator
public setBinaryBitsetLe ( string $bitset ) : void
$bitset string
return void
    public function setBinaryBitsetLe($bitset)
    {
        if (!is_string($bitset)) {
            throw new InvalidArgumentException('Bitset must be a string');
        }
        $size = strlen($this->bitset);
        $sizeIn = strlen($bitset);
        if ($sizeIn < $size) {
            // add "\0" if the given bitset is not long enough
            $bitset .= str_repeat("", $size - $sizeIn);
        } elseif ($sizeIn > $size) {
            $bitset = substr($bitset, 0, $size);
        }
        // truncate out-of-range bits of last byte
        $lastByteMaxOrd = $this->ordinalMax % 8;
        if ($lastByteMaxOrd === 0) {
            $this->bitset = $bitset;
        } else {
            $lastByte = chr($lastByteMaxOrd) & $bitset[$size - 1];
            $this->bitset = substr($bitset, 0, -1) . $lastByte;
        }
        // reset the iterator position
        $this->rewind();
    }