Serhiy Storchaka added the comment: Use bin(n & (2**bitsize-1)). ---------- nosy: +serhiy.storchaka _______________________________________ Python tracker <report at bugs.python.org> <http://bugs.python.org/issue25999> _______________________________________