Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #198062
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Lawrence D’Oliveiro <ldo@nz.invalid> |
| Newsgroups | comp.lang.python |
| Subject | Re: format_binary |
| Date | Thu, 24 Sep 2026 02:01:42 -0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 26 |
| Message-ID | <11920a6$29ujm$1@dont-email.me> (permalink) |
| References | <nnd$45c195ac$47172e6f@35c50d4e9a8c02a9> <bin-20260924000855@ram.dialup.fu-berlin.de> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Thu, 24 Sep 2026 02:01:43 +0000 (UTC) |
| Injection-Info | dont-email.me; logging-data="2423414"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jGin1SQprLL2cvTYKUb5X"; posting-host="4f6d7b10dcc8570e647aff25a58630fa" |
| User-Agent | Pan/0.165 (Kostiantynivka) |
| Cancel-Lock | sha1:p7iRJxLQ9tKkvDcMbRd9CiLew04= sha256:5FWjL3lv4yFxJ9qTcpa3nLNexk+cl3Jo53JXPLJ9ats= sha1:Resu/+tKK3raR4u7lzFI1Xs9NzQ= sha256:GJq1JEIayprjPMjbnR2R3Zu+/d5Tii5tbXBjRAnC+Zg= |
| Xref | csiph.com comp.lang.python:198062 |
Show key headers only | View raw
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
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