def toBinaryString()

in rtl/log/luts/FixedPoint.py [0:0]


    def toBinaryString(self, logBase=1, twosComp=True):
        """Convert number into string in base 2/4/8/16

        logBase -       log_2 of the number base for printing.
                        (e.g. 1 for binary, 3 for octal, 4 for hexadecimal).
                        This must be no greater than 4.
        twosComp -      Whether to convert negative numbers into
                        twos-complement form. If this is False,
                        then negative numbers are simply prefixed
                        by a minus sign.

        Note that when negative numbers are converted to twos-complement form,
        this may involve estimating how many bits are needed
        to contain the integer part if this is not specified by the FXfamily.
        """
        if not isinstance(logBase, int) or logBase > 4 or logBase < 1:
            raise ValueError('Cannot convert to base greater than 16')

        sign, prefix = 1, ''
        if self.scaledval < 0 and not twosComp:
            sign, prefix = -1, '-'
        (bits, intDigits, fracDigits) = \
                                (sign * self)._toTwosComplement(logBase)

        digits = []
        mask = (1 << logBase) - 1
        for dig in range(intDigits+fracDigits):
            digits.append('{:1x}'.format(bits & mask))
            bits >>= logBase
        digits = ''.join(reversed(digits))

        return prefix + digits[:-fracDigits] + '.' + digits[-fracDigits:]