Question

In this assignment, you will create a C program that iteratively populates a fixed-size integer array of 3 elements, array α.Endian Conversion ar raya [ 2] \t=\ t«VALUE 2 >binary| t«VALUE 2 >decimal丶t«VALUE 22hex - - 一 For example, the following outp

JUST GIVE ME THE C CODE FOR THIS QUESTION. I GOT THE ASSEMBLY CODE.

In this assignment, you will create a C program that iteratively populates a fixed-size integer array of 3 elements, array α.withhexadecimal integer valuesprovided by scanf. The user will enter 3 positive hexadecimal integer values, one per line, and the program will store the 3 values in arYay _afOJ,arvay aflJ, and crr ay_af2J. Once the 3 integers are entered, your program will print the array ain 32 bit binary, decimal, and hexadecimal format. Then your program will call an assembly procedure that will either perfom a Bit Reverse Order Operation or a convert operation between 8-bit Endians (little and big) Your program onl y needs to do one. Your assembly procedure will edit the contents of array a to their new values. Once completed, your procedure will return control to your C program Your C program will then print the mo dified array a in both decimal and hexadecimal format After all output has been displayed, the program should exit (do not prompt for additional input) Input will be entered by the user in the following form: VALUE O>ENTER> VALUE 1>ENTER> VALUE 2 Once all of the input is entered, output will be printed in the following format (where is one of the integers provided by the user) array ar0] t-\tbinary\tdecimall t hex array a[2] \t-\tbinary\tdecimall t hex If performing the Bit Reverse Order, the following output will be displayed once the operation is complete BIT REVERSE ORDER a[1]\t=\t«VALUE 1>binary丶t«VALUE 1-dec imalt«VALUE 12hex array If performing the Endian Conversion, the following output will be displayed once the op eration is complete: Endian Conversion a[0]\t=\t«VALUE 0>b inar y\t«VALUE 0>dec imal\t«VALUE 0>hex array
Endian Conversion ar raya [ 2] \t=\ t«VALUE 2 >binary| t«VALUE 2 >decimal丶t«VALUE 22hex - - 一 For example, the following output is displayed when the user enters (FF, 308, 44325A32) for the array values (both Bit Reverse Order and Endian conversion are shown, but only oneneeds to be present in your solution) ar raya [O] \t=\t000000000000000000000000 11111111\t255\tFF array a[1]\t-\ t00000000000000000000001100001000t7761t308 ar ray a[2]\t=\t01000100 0 0 1 100 100101101000110010\t1144150578\t44325A32 BIT REVERSE ORDER ar ray a[0]\t=\ t 1 1111111000000000000000000000000丶t4278190080\tFF00 0000 array a[1]\t-\t00010000110000000000000000000000 t 17563 648 t10co000 ar ray a[2]\t=\t0 1001100010110100100110000100010\t12809 8 6 14 6\t4C5A4C22 Endian Conversion ar ray a[0]\t=\ t 1 1111111000000000000000000000000丶t4278190080\tFF00 0000 ar ray a[1]\t=\t00001000 000000110000000000000000\t134414336\t08030000 array_a[2] t-t001100100101101000110010010001001t844771908 t325A3244
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

int main(void)
{
   unsigned int array_a[3],a;
int d,c,k,i;
   //%x for hex input
   printf("Enter hexadecimal value without \"0x\": ");
   scanf("%x", &array_a[0]);
printf("Enter hexadecimal value without \"0x\": ");
   scanf("%x", &array_a[1]);
printf("Enter hexadecimal value without \"0x\": ");
   scanf("%x", &array_a[2]);
//hex
   printf("array_a[0] = 0x%x \narray_a[1] = 0x%x \narray_a[2] = 0x%x \n", array_a[0],array_a[1],array_a[2]);
//decimal
printf("array_a[0] = %d \narray_a[1] = %d \narray_a[2] = %d \n", array_a[0],array_a[1],array_a[2]);
  
for(i=0;i<3;i++){
//pick one element at a time to convert
a = array_a[i];
//convert decimal to binary
//c starts from 31 as we are doing 32 bit representation
for (c = 31; c >= 0; c--)
{
k = a >> c;
//k is and with 1 if it is 1 output will be 1 0 otherwise
if (k & 1)
printf("1");
else
printf("0");
}

printf("\n");
}

   return 0;
}

output

Enter hexadecimal value without Ox: aa Enter hexadecimal value without Ox: 41 Enter hexadecimal value without Ox: 74 ar

Add a comment
Know the answer?
Add Answer to:
JUST GIVE ME THE C CODE FOR THIS QUESTION. I GOT THE ASSEMBLY CODE.
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
  • Write a program that allows the user to enter an unsigned integer (the maximum value of...

    Write a program that allows the user to enter an unsigned integer (the maximum value of an unsigned 4-byte int is 232 = 4,294,967,296) and reverses its format (from little to big endian, or vice versa). Print out the user-entered number in hexadecimal and binary, reverse the endianness, and print the reverse in hexadecimal and binary. Integers in most machine architectures are represented in little endian format: the least significant byte is stored in the smallest address; for instance, the...

  • Here is the code I made, but the test case is not working, it goes wrong...

    Here is the code I made, but the test case is not working, it goes wrong when the binary string convert to decimal. please help. #include "stdafx.h" #include <iostream> #include <string> #include <math.h> #include <locale> using namespace std; // function for option 1 void decToBin(int number) {        int array[16];        int i = 0;        for (int counter = 0; counter < 16; counter++)        {               array[counter] = 0;        }        while (number > 0)        {...

  • Finish the MARIE assembly language code below to determine the largest integer, the smallest integer, and...

    Finish the MARIE assembly language code below to determine the largest integer, the smallest integer, and the sum of integers for a sequence of 5 signed integers. The program already calculates the largest integer, just need it to calculate the smallest integer and the sum of the integers. The 5 integers should first be entered by the user via the input device. Your program is then assembled and run to determine the largest integer, the smallest integer, and the sum...

  • write codes and give detailed explanation of how to execute. What you need to turn in:...

    write codes and give detailed explanation of how to execute. What you need to turn in: You will need to include an electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named "labl-name," where "name" is your last name. Submit the zipped folder on the assignment page in Canvas; submit the report separately (not inside the zipped folder) as a Microsoft Word or PDF...

  • Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher...

    Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher is an encryption algorithm that encrypts 1 byte of plain text at a time. This one uses a given 4-bit bit pattern as the key. The size of the encrypted message that we want to be able to send has a maximum length of 200 characters. You must: 1. prompt the user to input the clear text to be encrypted. You must use printf()...

  • Using Microsoft Visual Studio. 1) Complete the following C++ program by adding more line of code...

    Using Microsoft Visual Studio. 1) Complete the following C++ program by adding more line of code for 8-bit signed array, 16-bit unsigned array, 16-bit signed array, 32-bit signed array and 32-bit signed array. 2) Fill in all the blanks in Table 1 using your completed code, following the hints provided within the table. 3) Fill in all the blanks in Table 2 using your completed code, following the hints provided within the table. C++ Program #include <stdio.h> #include <iostream> int...

  • Playing With Arrays The following problems are to give you practice with programming with arrays. Write...

    Playing With Arrays The following problems are to give you practice with programming with arrays. Write a program to: 1.Ask the user for numbers and place them in an array sequencially. 2.Next, print out the values in the array in the order they are stored. 3.Search the array for the postion containing the smallest value. 4.Print out the position where the smallest value was found. 5.Swap the smallest value with the value in the first postition of the array. 6.Print...

  • X86 Assembly language lab: TITLE Lab 3: assembly language fundamentals               ;;;;; Q1: Don't...

    X86 Assembly language lab: TITLE Lab 3: assembly language fundamentals               ;;;;; Q1: Don't forget to document your program            ; Name:Yuyan Wang ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Answer each question below by writing code at the APPROPRIATE places in the file. ;;;;; Hint: the appropriate place is not always right below the question. ;;;;; Q2: Write the directive to bring in the IO library           ;;;;; Q3: Create a constant called MAX and initialize it to 150...

  • The following problem concerns the following, low-quality code: void foo(int x) { int a[3]; char buf[1];...

    The following problem concerns the following, low-quality code: void foo(int x) { int a[3]; char buf[1]; a[1] = x; a[2] = 0xA0B1C2D3; gets(buf); printf("a[0] = 0x%x, a[2] = 0x%x, buf = %s\n", a[0], a[2], buf); } In a program containing this code, procedure foo has the following disassembled form on an x86/64 machine: 000000000040057d <foo>: 40057d: push %rbp 40057e: mov %rsp,%rbp 400581: sub $0x30,%rsp 400585: mov %edi,-0x24(%rbp) 400588: mov -0x24(%rbp),%eax 40058b: mov %eax,-0xc(%rbp) 40058e: movl $0xa0b1c2d3,-0x8(%rbp) 400595: lea -0x11(%rbp),%rax 400599:...

  • Please help me with the following C Programming project. I am providing the code I used...

    Please help me with the following C Programming project. I am providing the code I used which needs to be reworked to add the following requirements. Here is my code #include<stdio.h> char input; int main() { int i = 0; while (true){ scanf_s("%c", &input); if (input == 'X') break; printf("%c", input); } return 0; } Here are the requirements for the code plus and additional note what the code should have. Goals Understand the ASCII representation of character values. Understand...

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