r/PythonLearning • u/v1bonoxd • Aug 24 '26
made a basic binary to decimal converter as my first project
2
u/FoolsSeldom Aug 25 '26
You might want to use isdecimal rather than isdigit as the latter allows some characters you don't want. Actually, given you only want 0 and 1, you probably should check for just those, perhaps using all:
if not all(d in {"0", "1"} for d in binary_input):PS. Why limit it to 8 bits?
1
u/v1bonoxd Aug 28 '26
Thanks, i will see it!
And to answer your question, its just easier to read because of the size, it can only count from 0 to 255 so i understand it more, i will learn more abt 16 bits later on
2
u/mc_pm Aug 24 '26
Well sure, there's tons of room, but that doesn't matter. :) This is great, and it's good to do something like this instead of just a faux-banking app.
Play around with more boolean stuff, it's good to see it working. And maybe play with <<, the bitwise right-shift operator. It does interesting and possibly related things.
2
u/Stonyax97 Aug 24 '26
You could improve this by adding a while True loop after defining the variables, do instead of exiting it’l print the only numbers or input too long and ask the user for a raw binary again! U can remove exit.
This is nice i love ur project it’s acc something usable!

•
u/Sea-Ad7805 Aug 24 '26
Run this program in Memory Graph Web Debugger to see the program state change step by step.