def draw_bits(svg, id, x, y, prefix, numBits, bits, activeBits=None):
    # prefix is assumed to be a single character

    if (showBitsAs == "text"):
        draw_bits_as_string(svg, id, x, y, prefix, numBits, bits)
        return

    ob = SvgText(prefix, x, y, id=id)
    ob.set_style(nameStyle)
    svg.addElement(ob)

    x += dc.bitPrefixSkip
    y -= dc.bitHgt - 1

    if (activeBits == None):
        infBit = 1

    for bitNum in range(numBits):
        bitPos = numBits - 1 - bitNum
        bit = bits & (1 << bitPos)
        if (activeBits != None):
            infBit = activeBits & (1 << bitPos)

        if (bitGroupSizes == None): groupNum = 0
        else: groupNum = bitNum // bitGroupSizes[0]
        bitX = bitNum * dc.bitWdt + groupNum * dc.bitGroupSepWdt

        ob = SvgRect(x + bitX,
                     y,
                     dc.bitWdt,
                     dc.bitHgt,
                     id="%s_bit%d" % (id, bitNum))
        ob.set_stroke(dc.bitOutlineColor)
        ob.set_stroke_width(dc.bitOutlineThickness)
        if (infBit == 0): ob.set_fill(dc.bitXColor)
        elif (bit == 0): ob.set_fill(dc.bit0Color)
        else: ob.set_fill(dc.bit1Color)
        svg.addElement(ob)
def draw_bits_as_string(svg, id, x, y, prefix, numBits, bits):
    ob = SvgText(prefix + ":" + bits_to_string(numBits, bits), x, y, id=id)
    ob.set_style(nameStyle)
    svg.addElement(ob)