Question

Character Arrays Wri out the sum of the two numbers in hexadecimal. (As noted in class, first do this without using a file and by reading using the cin>-command) From Wikipedia: In mathematics and computer science, hexadecimal (also base 16, or hex) is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0-9 to represent values zero to nine, and A, B, C, D, E F (or alternatively a-0) to represent values ten to fifteen. For example, the hexadecimal number 2AF3 is equal, in decimal, to (2 × 16) + (10 × 16) + (15x 16) + 0-16) or 10,995. te a program that reads in two hexadecimal numbers from a file, hex dat, and prints and A, B, C, D,E For example, if the file contains: 4SAF 12B3 your program will output (if you output the result in decimal): The decimal sum of 45AF and 12B3 is 22626. (To check your results, you can go to a hexadecimal calculator on the web. For ple, http://www.csgnetwork.com/ To solve this problem: read the hexadecimal numbers as character arrays a) ) convert the character arrays to numbers (by calling a function that takes the character array as a parameter, and returns an integer) c) add the numbers to get a decimal sunm d) EXTRA CREDIT: convert the sum to hexadecimal (by calling a function that fills a character array) Assume that your file has an unknown number of hexadecimals. Change your program so that it prints the sum of all the numbers in the file.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

.MODEL SMALL
.STACK 100H
.DATA
MSG_1 EQU 'Enter the Hex digit (A-F) : $'
MSG_2 EQU 0DH,0AH,'The corresponding Decimal dgit is : $'
PROMPT_1 DB MSG_1
PROMPT_2 DB MSG_2
.CODE
MAIN
PROC MOV AX, @DATA
MOV DS, AX
LEA DX, PROMPT_1
MOV AH, 9
INT 21H
MOV AH, 1
INT 21H
MOV BL, AL
LEA DX, PROMPT_2
PROMPT_2
MOV AH, 9
INT 21H
MOV AH, 2
MOV DL, 31H
INT 21H
SUB BL, 11H
MOV DL, BL
INT 21H
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN

Add a comment
Know the answer?
Add Answer to:
Write a program that reads in two hexadecimal numbers from a file, hex.dat, and prints out...
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
  • (a) Hexadecimal numbers are numbers in base 16. They use the following sixteen digits: 0, 1,...

    (a) Hexadecimal numbers are numbers in base 16. They use the following sixteen digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. They are widely used in com- puting, for example, to represent colors or network addresses of computers. i. Convert A2F1316 to decimal. Show your work. ii. Convert 456710 into hexadecimal. Show your work. iii. Convert 00010101100011002 to hexadecimal. Explain how can you use the fact that 16 = 24 ?...

  • [Using Python] Write a program to convert a hexadecimal number to its decimal value. (Reminder: hexadecimal...

    [Using Python] Write a program to convert a hexadecimal number to its decimal value. (Reminder: hexadecimal numbers are 0 through 9, A,B,C,D,E,F. hex(A) = 10, hex(F) = 15). example outputs: 1. `Enter a hex number: f` `The decimal value for hex number f is 15` 2. `Enter a hex number: g` `Incorrect hex number` 3. `Enter a hex number: 091c` `The decimal value for hex number 091c is 2332` 4. `Enter a hex number: 091g` `Incorrect hex number` Hints: you...

  • Write a program file_max.c that reads a set of integer numbers from a file and prints...

    Write a program file_max.c that reads a set of integer numbers from a file and prints out the maximum number to standard output. The name of the input file should be specified as a command line argument.

  • Here is the Prompt for problem 1: Write a C++ program that reads in a test file. The first numbe...

    Here is the Prompt for problem 1: Write a C++ program that reads in a test file. The first number in the file will be an integer, and will indicate the amount of decimal numbers to follow. Once you have the read the numbers from the file into an array then compute the following properties on the set of numbers: the sum, the average (mean), the variance, the standard deviation, and the median. Don’t try to do the entire program...

  • Write a C program which will display the contents of a file in base-16 (hexadecimal) and...

    Write a C program which will display the contents of a file in base-16 (hexadecimal) and in ASCII. Complete the following tasks: Obtain the name of the input file from the command line. If the command-line is “./hexdump xxx.bin” then argv[1] will contain “xxx.bin”. Open the file for binary input Print the entire file, 16-bytes per line. Each line should begin with an 8-digit hexadecimal offset into the file. This is the count of the bytes that you have already...

  • C++ program to convert between decimal, hexadecimal, and octal. Please Help!!

    Hi, I need help writing a program that reads in data (hex, octal or decimal values) from an input file and outputs the values in to another base form (hex, octal,decimal) one line at a time depending on the formatting characters provided by the input file. I am posting the code requirements below and an example of what theinput file will look like and what should be output by the program. I only need the one .cpp program file. Thanks...

  • Java. (20 pts)          Write a program that reads all the numbers from the file mynums.dat...

    Java. (20 pts)          Write a program that reads all the numbers from the file mynums.dat and prints out the sum of the positive values from the file. Assume that the file contains only numeric values. You must output an error if the file can't be opened. You must write the complete program and the output when the program runs successfully must conform exactly to the sample output. Bonus ( 5 pts). Output an error if the file contains non-numeric...

  • Arrays and reading from a file USE C++ to write a program that will read a...

    Arrays and reading from a file USE C++ to write a program that will read a file containing floating point numbers, store the numbers into an array, count how many numbers were in the file, then output the numbers in reverse order. The program should only use one array and that array should not be changed after the numbers have been read. You should assume that the file does not contain more than 100 floating point numbers. The file name...

  • Write a program that reads in a text file, infile.txt, and prints out all the lines...

    Write a program that reads in a text file, infile.txt, and prints out all the lines in the file to the screen until it encounters a line with fewer than 4 characters. Once it finds a short line (one with fewer than 4 characters), the program stops. For your testing you should create a file named infile.txt. Only upload your Python program, I will create my own infile.txt. Please use a while-loop BUT do not use break, Exit or Quit...

  • 1. Write a program called Numbers that a. prompts the user for a file name. b....

    1. Write a program called Numbers that a. prompts the user for a file name. b. reads that file assuming that its contents consist entirely of integers. c. prints the maximum, minimum, sum, count (number of integers in the file), and average of the numbers. For example, if the file numberinput.dat has the following content: 4 -2 18 15 31 27 Your program should produce the following output: csc% java Numbers Enter file name: numberinput.daft Maximum31 Minimum- -2 Sum -...

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