simple java

Please answer the next 4 questions following the instructions of them -the way that the question ask for precisely- the first three parts in java – simple java. and the part 4 by c language.
—————————————————————–
Part 1. Using the bitwise operators (&, |, ^, ~, – (2’s complement/unary negation), <<, >>, and >>>) discussed in class, write a function in Java that swaps (returns) the byte order of an integer from one endian-ness to the other. A template for the Java function follows: 
static int swap ( int i ) {
.
.
.
}

Part 2. Using only the the arithmetic operators (+, -, *, /, %, and – (2’s complement/unary negation)), implement a Java function that also swaps the byte order of an integer (ifs are OK too). Note that it is actually much more difficult to do this using only the arithmetic operators! Hint: First implement it correctly for positive i, and only then begin working on the version that also handles negative i. A template for this Java function follows: 
static int swap2 ( int i ) {
.
.
.
}

Part 3. Using a timing methods such as the Java code below, time your swap and swap2 methods by repeatedly calling them many, many times. Report your results in the number of seconds required for one function call. 
final int N = 1000000;

long start = System.nanoTime();
for (int i=0; i<N; i++) {
int x = swap( 0x01020304 );
}
long elapsed = System.nanoTime() – start;
System.out.println( “elapsed time = ” + (elapsed/1E9/N) );

Furthermore, since C and C++ have pointer variables, another approach is possible. But please use only the bitwise ones in part 1, and only the arithmetic ones in part 2. Do not use any built in functions that may exist, and certainly do not manipulate them as strings! 

You are required to test your program using the following input: 0x01020304, 0x010203ff, 0xff020304, 0xfe020304, and 0x80aacc84. Email your code and output to me and our excellent TA. 

Part 4. Write a C program with a function that changes the byte order of an integer by treating it as an array of characters. The function should be defined as the following: 
void swap ( char* data ) {

}
It should be called like the following: int k = 0x0a0b0c0d;
swap( (char*) &k ); 
After swap, the byte order of k should become 0x0d0c0b0a

p(1)

Place your order now to enjoy great discounts on this or a similar topic.

People choose us because we provide:

Essays written from scratch, 100% original,

Delivery within deadlines,

Competitive prices and excellent quality,

24/7 customer support,

Priority on their privacy,

Unlimited free revisions upon request, and

Plagiarism free work,

 

Order Similar Assignment Now!

  • Our Support Staff are online 24/7
  • Our Writers are available 24/7
  • Most Urgent order is delivered within 4 Hrs
  • 100% Original Assignment Plagiarism report can be sent to you upon request.

GET 15 % DISCOUNT TODAY use the discount code PAPER15 at the order form.

Type of paper Academic level Subject area
Number of pages Paper urgency Cost per page:
 Total: