Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Binary to decimal script
#1
Hey,
I missed a coding class today and I didn't understand at all the script we have been given for homework. We are supposed to write and input and the output from the script but I still want to understand the script. The script converts a number in a binary base to decimal. (It's in the newest python version available as I am writing this).

bin_num = int(input("Insert binary number: "))
dec_num = 0
num = bin_num
m=0
while num>0:
  digit = num%10
  p = 2**m
  dec_num = dec_num+digit*p
  num=num//10
  m+=1


print(bin_num,"(2)= ",dec_num,"(10)")
print ("Name classmethod") 
Reply
#2
Nevermind.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple text to binary python script gmills13 2 2,804 Feb-04-2020, 08:44 PM
Last Post: snippsat
  hex file to binary or pcap to binary baran01 1 5,676 Dec-11-2019, 10:19 PM
Last Post: Larz60+
  Python script that calls jamfHelper binary kennethdean2010 19 7,116 May-07-2019, 03:50 PM
Last Post: kennethdean2010
  testing for Decimal w/o importing decimal every time Skaperen 7 4,425 May-06-2019, 10:23 PM
Last Post: Skaperen
  Converting Decimal to Binary emerger 1 2,789 Feb-27-2018, 08:06 PM
Last Post: Gribouillis
  Binary for Decimal Numbers emerger 1 2,657 Feb-26-2018, 06:06 PM
Last Post: Larz60+
  Converting an 8-bit binary to decimal WITHOUT the shortcuts EIA 5 6,984 Dec-01-2017, 09:04 AM
Last Post: stranac

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020