News for hackers. Stuff that matters.
Re:8-bit number to binary string by est on Thursday November 05, 2015 @11:41AM (#10514318)
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

There are no comments on this comment yet.