As the topic says, is. . .
''.join([bin(i)[2:].zfill(8) for i in flag])
really the most Pythonic way to do this?
I mean, isn't there a regular print-to-string-format function, something
akin to C's sprintf(), that does this in a more succinct way?
Here, `flag` is a string variable, if it's not clear from the con-
text.
Like,
''.join( f'{i:08b}' for i in flag )
?
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
Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> wrote or quoted:
As the topic says, is. . .
''.join([bin(i)[2:].zfill(8) for i in flag])
really the most Pythonic way to do this?
I mean, isn't there a regular print-to-string-format function, something
akin to C's sprintf(), that does this in a more succinct way?
Like,
''.join( f'{i:08b}' for i in flag )
?
Here, `flag` is a string variable, if it's not clear from the con-
text.
If "flag" would be a string, then "i" would be a string too,
but "bin" expects an integer.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 76 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 53:32:54 |
| Calls: | 1,265 |
| Calls today: | 1 |
| Files: | 1,362 |
| D/L today: |
3 files (2,684K bytes) |
| Messages: | 285,430 |