3 ms·
For Python >>> f1=lambda c: __import__('struct').pack('<Q', 3472328296227680304 + (((c * 9241421688590303745) / 128) & 72340172838076673)) >>> f1(1)
by est 11y ago
For Python
>>> f1=lambda c: __import__('struct').pack('<Q', 3472328296227680304 + (((c * 9241421688590303745) / 128) & 72340172838076673))
>>> f1(1)
'00000001'
>>> f1(2)
'00000010'
>>> f1(5)
'00000101'
>>> f2=lambda c: struct.pack('<Q', (((c * 0x8040201008040201) / 128) & 0x0101010101010101))
>>> f2(1)
'\x00\x00\x00\x00\x00\x00\x00\x01'
>>> f2(2)
'\x00\x00\x00\x00\x00\x00\x01\x00'
>>> f2(101)
'\x00\x01\x01\x00\x00\x01\x00\x01'
Use "<" for little-endian for x86