I'm not sure what I'm doing wrong, but my print statement doesn't seem to be working.
def nib(string):
if string == '0000':
return '0'
if string == '0001':
return '1'
if string == '0010':
return '2'
if string == '0011':
return '3'
if string == '0100':
return '4'
if string == '0101':
return '5'
if string == '0110':
return '6'
if string == '0111':
return '7'
if string == '1000':
return '8'
if string == '1001':
return '9'
if string == '1010':
return "A"
if string == '1011':
return "B"
if string == '1100':
return "C"
if string == '1101':
return "D"
if string == '1110':
return "E"
if string == '1111':
return "F"
def main(nib):
strings= input("Enter your 4 bit binary nibble, separated by spaces: ")
strings= strings.split(' ')
print(string)
I'd like to maintain the code in the simple format I have since I'm a beginner. Here are my instructions:
Write a function that takes as an argument, a 4 bit binary nibble represented as a string, and returns its hex equivalent value as a String
Use that function to write a program that accepts an entire string of binary nibbles entered from the keyboard and prints out the full hex equivalent. The nibbles in the input must be separated by spaces.
For Example:
An input of 0101 1101 produces an output of 5D An input of 0000 1001 0001 1111 1100 produces an output of 091FC
I don't know where I went wrong?????