Is there a way to make it 4 beats when changing Python binary?

Asked 2 years ago, Updated 2 years ago, 14 views

For example, if you do bin (5), It's ob101, but I want to know how to make it 0101 with 4 beats.

python

2022-09-21 19:22

2 Answers

You can do it as below.

format(5, '04b')

'0101'


2022-09-21 19:22

You can simply do it as follows.

format(5, 'b')


2022-09-21 19:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.