Question: Each function definition should include a docstring that describes what the function does, its arguments, and its returned value. 5. Define a Python function unsignedDecimalToBinary

Each function definition should include a docstring that describes what the function does, its arguments, and its returned value.
5. Define a Python function unsignedDecimalToBinary that expects an unsigned decimal integer as an argument and returns the corresponding string of binary digits. You should assume that the caller provides a correctly formed integer, so no error handling is necessary.
9. Using the functions you already have defined, define a function decimalToTwosComp that expects a signed decimal integer as an argument and returns the corresponding twos-complement string of binary digits.
10. Define a function signExtend that expects a twos complement string of binary digits and the total number of bits as arguments and returns the corresponding twos complement string of binary digits, sign-extended to that number of bits.
def invert(bitString): III Returns the bit string with the bits inverted." invertedString = " for bit in bitString: if bit == '1': invertedString += 'O. else: invertedString += '1' return invertedString def main(): "Test bed for decimal/binary conversion functions." print ("11001 ->", invert("00110")) print ("O ->", unsignedBinaryToDecimal("")). print ("6 ->", unsignedBinaryToDecimal("110")) print ("O ->", unsignedDecimalToBinary(0)) print ("110 ->", unsignedDecimalToBinary (6)) print ("110 ->", addone("101")) print ("5 ->", twosCompToDecimal("0101")) print ("-5 ->", twos CompToDecimal("1011")) print ("0101 ->", decimalToTwosComp (5)) print ("1011 ->", decimalToTwosComp(-5)). print ("00000101 ->", signExtend(decimalToTwosComp(5), 8)) print ("11111011 ->", signExtend(decimalToTwosComp(-5), 8)). if -_name__ == "__main__": main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
