Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #198063
| From | Jon Ribbens <jon+usenet@unequivocal.eu> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: format_binary |
| Date | 2026-09-24 06:57 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrn11b9if4.2kd.jon+usenet@raven.unequivocal.eu> (permalink) |
| References | <nnd$45c195ac$47172e6f@35c50d4e9a8c02a9> <bin-20260924000855@ram.dialup.fu-berlin.de> <11920a6$29ujm$1@dont-email.me> |
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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
''.join([bin(i)[2:].zfill(8) for i in flag]) Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-24 06:42 +0800
Re: ''.join([bin(i)[2:].zfill(8) for i in flag]) ram@zedat.fu-berlin.de (Stefan Ram) - 2026-09-23 23:09 +0000
Re: format_binary Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-24 02:01 +0000
Re: format_binary Jon Ribbens <jon+usenet@unequivocal.eu> - 2026-09-24 06:57 +0000
Re: ''.join([bin(i)[2:].zfill(8) for i in flag]) Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-25 23:25 +0800
csiph-web