You were just hired for a summer internship with one Atlanta\'s best software co
ID: 3551019 • Letter: Y
Question
You were just hired for a summer internship with one Atlanta's best software companies; however, on your first day of work you learn that for the next 3 months, the only job you will have is to convert binary (base 2) numbers into decimal numbers (base 10). You decide to write a script that will repetitively ask the user for a binary number and return its decimal equivalent until an illegal number (one containing digits other than 0 or 1) is entered. The number entered should contain only the digits 0 and 1. The rightmost digit has the value 2
Explanation / Answer
done = false; while ~done binary = input('Enter a binary number: '); done = binary 0 digit = mod(binary, 10); binary = floor(binary / 10); decimal = decimal + digit * mult; mult = mult * 2; end fprintf('decimal = %d ', decimal); end endRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.