Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have to create a program in Python that converts a decimal to a hexadecimal, then from hexadecimal to decimal. I have completed the conversion

I have to create a program in Python that converts a decimal to a hexadecimal, then from hexadecimal to decimal. I have completed the conversion and I take input from the user for the original "decimal", but I can't figure out how to get the second function to print the conversion of hexadecimal to decimal back without hardcoding. Code please. The output right now for "300' is "12C", "2545" (2545 is wrong).

image text in transcribed

udef decimal_to_hex(n): hexadecimal = ['0'] * 100; while (n != 0): temp temp = n % 16; int(n / 16); if (temp = 0l: print((hexadecimal[j]), end=""); j = j - 1 ##n = 2545; n = int(input('Enter a decimal: ')) decimal_to_hex(n); udef hex_to_decimal(hex): hex [::-1].upper() hex %3D p = 1 for c in hex: if c in "ABCDEF": n += (ord(c) - ord('A')+10) *p else: n += (ord(c) - ord('0'))*p p *= 16 print (" ") print(n) hex_to_decimal("9F1")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

3030302776, 978-3030302771

More Books

Students also viewed these Databases questions