Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    To add underscores: f'0b{z:09_b}' => '0b0000_0011' Commented Oct 23, 2020 at 10:34
  • what about endianness? can one change it? Commented Oct 26, 2020 at 11:24
  • This is out of scope of this question. The most significant first is the canonical way how to write number in positional system regardless of system endianness which is just an implementation detail. You can do f'{z:08b}'[::-1] to achieve the least significant byte first ordering, however this will IMHO in most cases cause just confusion... Commented Oct 26, 2020 at 18:08
  • 2
    f strings also appear to be faster than format(). timeit.timeit( 'f"{2:08b}"', number=10000000 ) => 1.1823169720000806 versus timeit.timeit( 'format(2,"08b")', number=10000000 ) => 1.3507722609992925 Commented Aug 5, 2022 at 16:23