Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function to change variable from little endian to big endian notation Th

ID: 3726115 • Letter: W

Question

Write a function to change variable from little endian to big endian notation

The basic structure of the function is given in the attached assembly language file. You are expected to complete the function int toBigEndian(int variable) which converts an integer variable passed from little endian to big endian notation. The conversion function should simply accept the number variable and flip the order of the bytes and return the resulting value. For example Variable passed to function 0xAABBCCDD The value returned from the function 0xDDCCBBAA Complete the function implementation which takes a little endian notation as input and returns the big endian notation of the given value from the function as given in the above example. The function with the basic commands for the function entry and exit / return are already given.

write your code in C language

use main () function given, do not need printf or scanf in your C code since values are already given in the main function

#include <stdio.h>

#include "Hw5function.h"

int main() {

int in1, in2;

int out1, out2;

// Sample input value (It may be tested with other input values)

// Do not hard code these values inside the function

in1 = 0xAABBCCDD;

out1 = toBigEndian(in1);

printf(" Output1: %d", out1);

// Sample input value (It may be tested with other input values)

// Do not hard code these values inside the function

//Hw5function.h

extern int toBigEndian(int);

Explanation / Answer

main.c:

#include <stdio.h>

#include "Hw5function.h"

int main() {

int in1, in2;

int out1, out2;

// Sample input value (It may be tested with other input values)

// Do not hard code these values inside the function

in1 = 0xAABBCCDD;

out1 = toBigEndian(in1);

printf(" Output1: %d", out1);

// Sample input value (It may be tested with other input values)

// Do not hard code these values inside the function

Hw5function.h:

extern int toBigEndian(int x)

{

//converting from little endian to big endian

return (((x>>24) & 0x000000ff) | ((x>>8) & 0x0000ff00) | ((x<<8) & 0x00ff0000) | ((x<<24) & 0xff000000));

}

Out put:

nOutput1:0xDDCCBBAA

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote