JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

decimal to bin .py (prolly ahh) | JustPaste.app
12 days ago17 views
👨‍💻Programming

decimal to bin .py (prolly ahh)

#input and variables
decimal = input("decimal (lower than 512) > ")

#baby proof


if bool(decimal.isdigit()) == False:
    print("ERROR: Not a Number (Decimals are not allowed)")
    exit()

# variables 2
decimal = int(decimal)
# baby proof 2
if decimal > 512:
    print("ERROR: Decimal > 512")
    exit()
if decimal < 0:
    print("ERROR: Decimal < 0")
    exit()
# main compute
if decimal >= 256:
    decimal = decimal - 256
    output = "1"
else:
    output = "0"

if decimal >= 128:
    decimal = decimal - 128
    output = output + "1"
else:
    output = output + "0"

if decimal >= 64:
    decimal = decimal - 64
    output = output + "1"
else:
    output = output + "0"

if decimal >= 32:
    decimal = decimal - 32
    output = output + "1"
else:
    output = output + "0"

if decimal >= 16:
    decimal = decimal - 16
    output = output + "1"
else:
    output = output + "0"

if decimal >= 8:
    decimal = decimal - 8
    output = output + "1"
else:
    output = output + "0"

if decimal >= 4:
    decimal = decimal - 4
    output = output + "1"
else:
    output = output + "0"

if decimal >= 2:
    decimal = decimal - 2
    output = output + "1"
else:
    output = output + "0"

if decimal >= 1:
    decimal = decimal - 1
    output = output + "1"
else:
    output = output + "0"

# print
print("binary is:", output)
← Back to timeline