Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is Python Question and I need help! 2. (Write a method to convert hex to binary) The method should be named hex2bin and should

This is Python Question and I need help!

image text in transcribed

2. (Write a method to convert hex to binary) The method should be named hex2bin and should take 1 argument. The argument is a string of hex digits. Scanning from left to right, for each hex digit: a. Verify it is, in fact, a hex digit 0-9, a-f (or A-F). If it is not, issue an error and return '0' to the caller b. For each digit, convert the digit to a string of 4 bits (i.e.9-1001', A-> 1010', etc. Return the final string (a concatenation of all binary strings converted from hex) (Write a method to convert binary to hex) For this method, it should take a string of bits (as generated from hex2bin). Call this method bin2hex. Convert each set of 4 bits into a hexadecimal digit (hint: you can do this by taking the 4 bits, converting them to integer values and using a lookup in a list holding the 16 hex digits). Important! Remember to convert the bit sequence from right to left! 3. 4. (Test code) Write a short main method that calls hex2bin with a few different values containing at least 3-4 hexidecimal digits. Take the returned values and pass them to bin2hex. Look at the return value and make sure it matches with the original argument to hex2bin 5. Write a method that converts binary strings to octal strings. This conversion is very similar to the bin2hex conversion but the binary is divided into strings of 3 bits (still going from right to left.) Add a couple of tests to your main method giving binary strings you returned from hex2bin and show the hex value and the octal equivalent as output

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_2

Step: 3

blur-text-image_3

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions