Question

Using LC3 Editor. This program accepts an integer typed in by the user, verifies that the...

Using LC3 Editor. This program accepts an integer typed in by the user, verifies that the number is valid, and if it is valid prints the binary version of the number to the display as on the following page. Call the program part2.asm. As you can see the program rejects any input which doesn't start with a + or - sign and prints "The input is invalid." to the display. Also any integer values less than -511 or greater than +511 are rejected. Values like +0123 are acceptable. When a value is rejected the program loops back and asks for a new number. The program stops after printing out the binary representation of the entered number, with a space between each pair of bits.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

int binary_conversion(int);

int main()

{

int num, bin;

printf("Enter a number: ");

scanf("%d", &num);

If (num>=-511 && num<=+511)

bin = binary_conversion(num);

else

{

printf("Number is invalid enter the number again : ");

printf("Enter a number: ");

scanf("%d", &num);

}

printf("The binary equivalent of %d is %d\n", num, bin);

}

int binary_conversion(int num)

{

if (num == 0)

{

return 0;

}

else

{

return (num % 2) + 10 * binary_conversion(num / 2);

}

}

Add a comment
Know the answer?
Add Answer to:
Using LC3 Editor. This program accepts an integer typed in by the user, verifies that the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using java Sample Outputs Write a program which asks the user for an integer and then...

    Using java Sample Outputs Write a program which asks the user for an integer and then prints the following patterns based on that integer. Input Validation For Pattern 1, the input must be a value between 1 and 999 For Pattern 2, the input must be a value between 1 and 26. Requirements: For Pattern 1: must be able to work with up to three digit numbers. You will want to use printf to get the spacing correct. For Pattern...

  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...

  • In C++ 1. Write a program that allows a user to enter 10 integer values from...

    In C++ 1. Write a program that allows a user to enter 10 integer values from the keyboard. The values should be stored in an array. 2. The program should then ask the user for a number to search for in the array: The program should use a binary search to determine if the number exists in a list of values that are stored in an array (from Step #1). If the user enters a number that is in the...

  • Wrote a program called ExceptionalDivide that asks the user for 2 integer values and displays the...

    Wrote a program called ExceptionalDivide that asks the user for 2 integer values and displays the quotient of the first value divided by the second value. Make sure the your program reads in the two input values as ints. Your program must catch either of two exceptions that might arise and crash your program java.util.InputMismatchException //wrong data type inputted java.lang.ArithmeticException //divide by zero error Once you catch these exceptions, your program must print out a message explaining what happened and...

  • Implement a Java program using simple console input & output and logical control structures such that...

    Implement a Java program using simple console input & output and logical control structures such that the program prompts the user to enter 5 integer scores between 0 to 100 as inputs and does the following tasks For each input score, the program determines whether the corresponding score maps to a pass or a fail. If the input score is greater than or equal to 60, then it should print “Pass”, otherwise, it should print “Fail”. After the 5 integer...

  • Course, Schedule, and ScheduleTester (100%) Write a JAVA program that meets the following requirements: Course Class Cr...

    Course, Schedule, and ScheduleTester (100%) Write a JAVA program that meets the following requirements: Course Class Create a class called Course. It will not have a main method; it is a business class. Put in your documentation comments at the top. Be sure to include your name. Course must have the following instance variables named as shown in the table: Variable name Description crn A unique number given each semester to a section (stands for Course Registration Number) subject A...

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • USING C# 1. Write a program that takes outputs a string, an integer and a floating-point number s...

    USING C# 1. Write a program that takes outputs a string, an integer and a floating-point number separated by commas. Sample output: Bob Marley, 20, 5.2 2. 2. Write a program that asks the user for a string of letters of any size (no spaces), and finally a special character (values 33 to 47 in the Ascii table, or ‘!’ to ‘/’). Generate a random number of any size, integer or floating point, and combine those three pieces of information...

  • Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program...

    Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program named GetIDAndAge that continually prompts the user for an ID number and an age until a terminal 0 is entered for both. If the ID and age are both valid, display the message ID and Age OK. Throw a DataEntryException if the ID is not in the range of valid ID numbers (0 through 999), or if the age is not in the range...

  • Program 2 #include #include using namespace std; int main() { int total = 0; int num...

    Program 2 #include #include using namespace std; int main() { int total = 0; int num = 0; ifstream inputFile; inputFile.open("inFile.txt"); while(!inputFile.eof()) { // until we have reached the end of the file inputFile >> num; total += num; } inputFile.close(); cout << "The total value is " << total << "." << endl; Lab Questions: We should start by activating IO-exceptions. Do so using the same method in Step 3 of the Program 1 assignment above, except that instead...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT