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()
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
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()](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F3a5e8787-53bc-4ea8-9359-4f8c331cd409%2F489f5a83-9a60-4ca5-86f5-0d417a5e8d05%2Fdc0zso_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)