Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I haven't learnt about the while, for statement how can I do this question ? byte = '{}{}{}{}{}{}{}{}}'.format{a, b, c, d, e, f, g, h}
I haven't learnt about the while, for statement how can I do this question ?
byte = '{}{}{}{}{}{}{}{}}'.format{a, b, c, d, e, f, g, h} a = decimal % 2 b = (decimal//2) % 2 c = ((deciaml//2)//2) % 2 d = (((deciaml//2)//2)//2) % 2 e = (((deciaml//2)//2)//2) % 2 f = ((((deciaml//2)//2)//2)//2) % 2 g = (((((deciaml//2)//2)//2)//2)//2) % 2 h = (((((deciaml//2)//2)//2)//2)//2) % 2 return byte
I can only figure it out like this
Thank you for your help, I really appreciate it
3.2 Decimal-to-Byte Calculator In [67]: > # decimal-to-byte calculators executed in 33ms, finished 00:21:26 2020-09-06 decimal 40 byte: 00100100 Exercise Assign to byte a string of 8 bits that represents the value of decimal , a non-negative decimal integer from 0 to 28 1 = 255. Hint: Use // and %. In [ ]: def decimal_to_byte(decimal): # YOUR CODE HERE byte = a + b + C + d + e + f a = 1 g+h return byte executed in 8ms, finished 10:44:54 2020-09-09 In [ ]: == 8 # tests def test_decimal_to_byte(byte, decimal): byte_ = decimal_to_byte(decimal) correct = byte == byte_ and isinstance (byte, str) and len(byte) if not correct: print fi{decimal} should be represented as the byte {byte), not {byte_}. ) assert correct test_decimal_to_byte('01100111', 103) test_decimal_to_byte('00000011', 3) test_decimal_to_byte('00011100', 28) executed in 7ms, finished 10:44:54 2020-09-09 In [ ]: # decimal-to-byte calculator executed in 33ms, finished 10:44:55 2020-09-09Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started