• Re: format_binary

    From Lawrence D?Oliveiro@3:633/10 to All on Thu Sep 24 02:01:42 2026
    On 23 Sep 2026 23:09:14 GMT, Stefan Ram wrote:

    Like,

    ''.join( f'{i:08b}' for i in flag )

    ?

    def format_binary(n : int) :
    assert n >= 0
    return \
    "".join \
    (
    chr(ord("0") + (n & 1 << i != 0))
    for i in range(math.floor(math.log(max(n, 1)) / math.log(2)), -1, -1)
    )
    #end format_binary

    Sample results:

    ldo@theon:python_try> ./format_binary 15
    15 => 0b1111
    ldo@theon:python_try> ./format_binary 16
    16 => 0b10000
    ldo@theon:python_try> ./format_binary 17
    17 => 0b10001

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Jon Ribbens@3:633/10 to All on Thu Sep 24 06:57:40 2026
    On 2026-09-24, Lawrence D?Oliveiro <ldo@nz.invalid> wrote:
    On 23 Sep 2026 23:09:14 GMT, Stefan Ram wrote:

    Like,

    ''.join( f'{i:08b}' for i in flag )

    ?

    def format_binary(n : int) :
    assert n >= 0
    return \
    "".join \
    (
    chr(ord("0") + (n & 1 << i != 0))
    for i in range(math.floor(math.log(max(n, 1)) / math.log(2)), -1, -1)
    )
    #end format_binary

    Well, that is the absolute worst of all possible ways to do it, yes.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)