def binToDec(binary_input): decimal_number=0 steps_counter=0 while(binary_input>0): step_one=binary_input//10 step_two=binary_input%10 decimal_number=decimal_number+step_two*2**steps_counter steps_counter+=1 binary_input=step_one return decimal_number def decToHex(decimal_number): return_value="" decimal_digit=0 while (decimal_number!=0): hex_number=decimal_number%16|| if decimal_number<10: return decimal_number if decimal_number==10: return "A" if decimal_number==11: return "B" if decimal_number==12: return "C" if decimal_number=313: return "D" if decimal_number=D=14: return "E" if decimal_number==15: return "E" decimal_number=Ddecimal_number//16 return return_value def main(): binary_input=int(input ("Please enter a binary number: ")) decimal_number=binToDec(binary_input) print ("You entered the hexadecimal number:", decToHex(decimal_number)) main()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

Hello, this code attempts to convert a binary input into a hexadecimal output using 3 functions and basic python knowledge. The code works for the first 4 binary digits but does not work for anything further, almost as if the code isn't re-running and adding to the output. I am not sure what is happening.

def binToDec(binary_input):
decimal_number=0
steps_counter=0
while(binary_input>0):
step_one=binary_input//10
step_two=binary_input%10
decimal_number=decimal_number+step_two*2**steps_counter
steps_counter+=1
binary_input=step_one
return decimal_number
def decToHex(decimal_number):
return_value=""
decimal_digit=0
while (decimal_number!=0):
hex_number=decimal_number%16||
if decimal_number<10:
return decimal_number
if decimal_number==10:
return "A"
if decimal_number==11:
return "B"
if decimal_number==12:
return "C"
if decimal_number=313:
return "D"
if decimal_number==14:
return "E"
if decimal_number=315:
return "E"
decimal_number=Ddecimal_number//16
return return_value
def main():
binary_input=int(input ("Please enter a binary number: "))
decimal_number=binToDec(binary_input)
print ("You entered the hexadecimal number:", decToHex(decimal_number))
main()
Transcribed Image Text:def binToDec(binary_input): decimal_number=0 steps_counter=0 while(binary_input>0): step_one=binary_input//10 step_two=binary_input%10 decimal_number=decimal_number+step_two*2**steps_counter steps_counter+=1 binary_input=step_one return decimal_number def decToHex(decimal_number): return_value="" decimal_digit=0 while (decimal_number!=0): hex_number=decimal_number%16|| if decimal_number<10: return decimal_number if decimal_number==10: return "A" if decimal_number==11: return "B" if decimal_number==12: return "C" if decimal_number=313: return "D" if decimal_number==14: return "E" if decimal_number=315: return "E" decimal_number=Ddecimal_number//16 return return_value def main(): binary_input=int(input ("Please enter a binary number: ")) decimal_number=binToDec(binary_input) print ("You entered the hexadecimal number:", decToHex(decimal_number)) main()
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education