Get flags as a BitString.
Unused bits are set accordingly. Trailing zeroes are not stripped.

@return BitString
168800
public function bitString(): BitString
    {
        $last_octet_bits = $this->_width % 8;
        $unused_bits = $last_octet_bits ? 8 - $last_octet_bits : 0;
        return new BitString($this->_flags, $unused_bits);
    }
1294205
public function getnonceStr()
    {
        static $nonceStr;
        if (!$nonceStr) {
            $chars    = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
            $nonceStr = '';
            for ($i = 0; $i < 16; $i++) {
                $nonceStr .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
            }
        }

        return $nonceStr;
    }
880959
public BitArray getUnalignedBitString(boolean tagImplicit)
    throws IOException {
        if (!tagImplicit) {
            if (tag != tag_BitString)
                throw new IOException("DerValue.getBitString, not a bit string "
                                       + tag);
            }
        return buffer.getUnalignedBitString();
    }
402988
public function readShortstr()
    {
        $this->_bitcount = $this->_bits = 0;
        list(, $slen) = unpack('C', $this->_rawread(1));
        return $this->_rawread($slen);
    }
72718
public function number(): string
    {
        $num = gmp_import($this->_flags, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
        $last_octet_bits = $this->_width % 8;
        $unused_bits = $last_octet_bits ? 8 - $last_octet_bits : 0;
        $num >>= $unused_bits;
        return gmp_strval($num, 10);
    }
966511
private function getBitflags(array $flags)
    {
        $val = null;
        foreach ($flags as $flag) {
            $val = $val | $flag;
        }

        return $val;
    }
14548
public String getString()
    {
        int len=getInt();
        if (len==0xFFFF)
            return null;
        try
        {
            String s=new String(_buf,_pos,len,StringUtil.__ISO_8859_1);
            _pos+=len+1;
            return s;
        }
        catch (IndexOutOfBoundsException e)
        {
            // Bad request!!!
            LogSupport.ignore(log,e);
            return null;
        }
        catch (UnsupportedEncodingException e)
        {
            log.fatal(e);
            System.exit(1);
            return null;
        }
    }
1052252
function getSymbolicString(bitmask, valueToName, zeroName) {
    const matchingFlagNames = [];

    for (const k in valueToName) {
      if (bitmask & valueToName[k]) {
        matchingFlagNames.push(k);
      }
    }

    // If no flags were matched, returns a special value.
    if (matchingFlagNames.length === 0) {
      return zeroName;
    }

    return matchingFlagNames.join(' | ');
  }
500792
public function getIntegerPart()
	{
		if ( ! $this->getIsDecimal() ) return $this->_value;
		return substr( $this->_value, 0, strpos( $this->_value, "." ) );
	}
1191364
function flagsToStr(flags) {
	if (!flags) {
		return;
	}

	var buff = new Buffer(4);
	buff.writeUInt32BE(flags, 0);

	// return a 0-byte terminated or 4-byte string

	switch (0) {
	case buff[0]:
		return;
	case buff[1]:
		return buff.toString('utf8', 0, 1);
	case buff[2]:
		return buff.toString('utf8', 0, 2);
	case buff[3]:
		return buff.toString('utf8', 0, 3);
	default:
		return buff.toString();
	}
}
628427
public static String flagNames(long flags) {
        StringBuilder sbuf = new StringBuilder();
        int i = 0;
        long f = flags & StandardFlags;
        while (f != 0) {
            if ((f & 1) != 0) {
                sbuf.append(" ");
                sbuf.append(flagName[i]);
            }
            f = f >> 1;
            i++;
        }
        return sbuf.toString();
    }
1299719
public byte[] getBitString(int len) throws IOException {
        if (len > available())
            throw new IOException("short read of bit string");

        if (len == 0) {
            throw new IOException("Invalid encoding: zero length bit string");
        }

        int numOfPadBits = buf[pos];
        if ((numOfPadBits < 0) || (numOfPadBits > 7)) {
            throw new IOException("Invalid number of padding bits");
        }
        // minus the first byte which indicates the number of padding bits
        byte[] retval = new byte[len - 1];
        System.arraycopy(buf, pos + 1, retval, 0, len - 1);
        if (numOfPadBits != 0) {
            // get rid of the padding bits
            retval[len - 2] &= (0xff << numOfPadBits);
        }
        skip(len);
        return retval;
    }
588257
def byte(self):
        """"""
        flags = int(self._in_use) << 7 \
            | int(self._controller) << 6 \
            | int(self._bit5) << 5 \
            | int(self._bit4) << 4 \
            | int(self._used_before) << 1
        return flags
885575
public String toBitString(long value, int bits) {
        StringBuilder sb = new StringBuilder(bits);
        long lastBit = 1L << 63;
        for (int i = 0; i < bits; i++) {
            if ((value & lastBit) == 0)
                sb.append('0');
            else
                sb.append('1');

            value <<= 1;
        }
        return sb.toString();
    }
972236
public function getEnclosingRectangle() : ?array
    {
        $left = $this->width;
        $top = $this->height;
        $right = -1;
        $bottom = -1;

        for ($y = 0; $y < $this->height; ++$y) {
            for ($x32 = 0; $x32 < $this->rowSize; ++$x32) {
                $bits = $this->bits[$y * $this->rowSize + $x32];

                if (0 !== $bits) {
                    if ($y < $top) {
                        $top = $y;
                    }

                    if ($y > $bottom) {
                        $bottom = $y;
                    }

                    if ($x32 * 32 < $left) {
                        $bit = 0;

                        while (($bits << (31 - $bit)) === 0) {
                            $bit++;
                        }

                        if (($x32 * 32 + $bit) < $left) {
                            $left = $x32 * 32 + $bit;
                        }
                    }
                }

                if ($x32 * 32 + 31 > $right) {
                    $bit = 31;

                    while (0 === BitUtils::unsignedRightShift($bits, $bit)) {
                        --$bit;
                    }

                    if (($x32 * 32 + $bit) > $right) {
                        $right = $x32 * 32 + $bit;
                    }
                }
            }
        }

        $width = $right - $left;
        $height = $bottom - $top;

        if ($width < 0 || $height < 0) {
            return null;
        }

        return [$left, $top, $width, $height];
    }
487268
public BitArray getUnalignedBitString() throws IOException {
        if (buffer.read() != DerValue.tag_BitString)
            throw new IOException("DER input not a bit string");

        int length = getLength(buffer) - 1;

        /*
         * First byte = number of excess bits in the last octet of the
         * representation.
         */
        int validBits = length*8 - buffer.read();

        byte[] repn = new byte[length];

        if ((length != 0) && (buffer.read(repn) != length))
            throw new IOException("short read of DER bit string");
        return new BitArray(validBits, repn);
    }
737939
def get_access_flags_string(self):
        
        if self.access_flags_string == None:
            self.access_flags_string = get_access_flags_string(
                self.get_access_flags())

            if self.access_flags_string == "":
                self.access_flags_string = "0x%x" % self.get_access_flags()
        return self.access_flags_string