Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ctal numbers have a base of eight and the digits 07. Write the scripts octalToDecimal.py and decimalToOctal.py , which convert numbers between the octal and

ctal numbers have a base of eight and the digits 07. Write the scripts octalToDecimal.py and decimalToOctal.py, which convert numbers between the octal and decimal representations of integers.

These scripts use algorithms that are similar to those of the binaryToDecimal and decimalToBinary scripts developed in the Section: Strings and Number Systems.

An example of octalToDecimal.py input and output is shown below:

Enter a string of octal digits: 234 The integer value is 156

An example of decimalToOctal.py input and output is shown below:

Enter a decimal integer: 27 Quotient Remainder Octal 3 3 3 0 3 33 The octal representation is 33

""" File: binarytodecimal.py Converts a string of bits to a decimal integer. """ # Convert binary to decimal bitString = input("Enter a string of octal digits: ") decimal = 0 exponent = len(bitString) - 1 for digit in bitString: decimal = decimal + int(digit) * 2 ** exponent exponent = exponent - 1 print("The integer value is", decimal) # Convert decimal to binary bitString = int(input("Enter a decimal integer: ")) if decimal == 0: print(0) else: print("Quotient Remainder Binary") bitString = "" while decimal > 0: remainder = decimal % 2 decimal = decimal // 2 bitString = str(remainder) + bitString print("The binary representation is", bitString) exponent = len(bstring) - 1 for digit in bstring: decimal = decimal + int(digit) * 2 ** exponent exponent = exponent - 1 print("The integer value is", decimal)

""" File: decimaltobinary.py Converts a decimal integer to a string of bits. """

decimal = int(input("Enter a decimal integer: ")) if decimal == 0: print(0) else: print("Quotient Remainder Binary") bstring = "" while decimal > 0: remainder = decimal % 2 decimal = decimal // 2 bstring = str(remainder) + bstring print("%5d%8d%12s" % (decimal, remainder, bstring)) print("The binary representation is", bstring)

These codes are already presented and from these codes and directions, you have to figure out how to do decimaltooctal and octaltodecimal.

We are using the newest form of python which I believe is 3.

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

Building The Data Lakehouse

Authors: Bill Inmon ,Mary Levins ,Ranjeet Srivastava

1st Edition

1634629663, 978-1634629669

More Books

Students also viewed these Databases questions