Oh, once upon a time there was a one, two, and four byte representation I ditched it for the one or four byte representation used now.
We've not experienced any performance problems with the operations you mention. PL/pgSQL isn't all that slow, queries are pre-compiled and stored so it's just a matter of executing the PL/pgSQL bytecode and the query tree.
None of queries involved refer to any database table, they operate on a bitstring parameter. It's roughly equivalent to doing such operations in any compiled interpretive language, probably a bit slower than Tcl because PL/pgSQL and the query executor aren't optimized for doing simple operations rather than "real" (complex) SQL queries but probably not enough for us to care.