Write a c program that compiles and runs without errors

Assignment Help Computer Engineering
Reference no: EM132194673

Question :

Write a C program that compiles and runs without errors or warnings. This program has a bunch of little bit-manipulation functions in it. Your function prototypes should match the ones Igive here. Your main function should call each of your other functions. The purpose of your main function is to convince you that your other functions are working properly.

You may assume that your program is running in an environment that has 32-bit unsigneds and 64-bit unsignedlong longs, as the MS VS environment does.

When we speak of the position of a bit, let's follow the convention that the position of the lowest-order bit isposition 0. The rightmost (lowest-order) bit of an unsigned is bit #0, and the leftmost (highest-order) bit of anunsigned is bit #31.

Let's say that when we say bit field (12,7], we mean the collection of the following 5 bits:bit #7, bit #8, bit #9, bit #10, and bit #11 (not bit #12). The number on the right (next to the bracket) is theposition of the lowest-order bit in the bit field, while the number on the left (next to the parenthesis) is theposition of the first bit past the bit field. Bit field (5, 5] contains no bits. Bit field (6,5] contains one bit (namely,bit #5). Bit field (32.0] contains all 32 bits, starting with bit #0 and ending with bit #31.

As always, you are free to have your functions call other functions. On this assignment, you can save yourself significant time by doing this. It's smart to read through the assignment and see where you want to have your functions delegate some of their work to other functions.

0. void show( unsigned n );

Output the 32 bits of the arg, MSB first, with spaces separating the bytes, and a newline at the end.

(MSB = Most Significant Bit = highest-order bit,

LSB = Least Significant Bit = lowest-order bit)

For example, if main says

show( 0xBadDecafU );

then the output should be

10111010 11011101 11101100 10101111

1. void show64( unsigned long long nn );

Just like show, but now our arg is an unsigned long long. Recall that C (unlike C++) has no functionoverloading, so we have to give the 32-bit and 64-bit versions of the function different names.

For example, if main says

show64( 0xFeedFaceDeadBeefULL );

then the output should be

11111110 11101101 11111010 11001110 11011110 10101101 10111110 11101111

2. unsigned f0( unsigned n );

Returns the result of messing around with the bits of n in the following way:

Starting with n, turn on the bits in bit field (5,0]. (Recall that bit field (5,0] means bit #0, bit #1, bit #2, bit #3, and bit #4 (not bit #5).)

Flip the bits (10,5].

Turn off the bits (15,10].

Swap bit fields (20, 15] and (25, 20]. For instance, if bit field (20,15] held 11011 and bit field (25,20]held 01101, then after the swap bit field (20,15] would hold 01101 and bit field (25,20] would hold 11011.

Leave the bits (32, 25] the same as they were originally in n.

For example, f0( 0xBadDecafU ) returns 0xBBB6835FU:

n: 1011101 01101 11011 11010 00101 01111

f0(n): 1011101 11011 01101 00000 11010 11111

The function does no I/O, though of course main can output the returned value if it wants.

3. unsigned long long f1( unsigned long long nn );

(Similar to f0, but with 64-bit values)

Starting with nn, flip the bits in (8, 0].

Swap bit fields (16, 8] and (32, 24], leaving (24, 16] unchanged

Reset the bits in (40, 32] to 0.

Leave the bits in (56), 40] unchanged.

Set the bits in (64, 56] to 1.

For example, f1( 0xFeedFaceDeadBeefULL ) returns 0xFFEDFA00BEADDE10ULL:

nn: 11111110 11101101 11111010 11001110 11011110 10101101 10111110 11101111

f1(nn): 11111111 11101101 11111010 00000000 10111110 10101101 11011110 00010000

4. unsigned number1Bits( unsigned n );

Returns the number of 1-bits in n.

For example, number1Bits( 0xBadDecafU ) returns 22.


5. unsigned number1Bits64( unsigned long long nn );

Just like number1Bits, but this is the 64-bit version.

For example, number1Bits64( 0xFeedFaceDeadBeefULL ) returns 48.

6. unsigned number0Bits( unsigned n );

Same as number1Bits, but now we're returning the number of 0-bits instead of the number of 1-bits.

For example, number0Bits( 0xBadDecafU ) returns 10.

7. unsigned number0Bits64( unsigned long long nn );

64-bit version.

For example, number0Bits64( 0xFeedFaceDeadBeefULL ) returns 16.

8. unsigned lowBitPosition( unsigned n );

Returns the position of the lowest-order 1-bit in n.

For example, lowBitPosition( 0x0F0ABCC0U ) returns 6.

If there are no 1-bits, then the function should return 32.

9. unsigned lowBitPosition64( unsigned long long nn );

64-bit version.

For example, lowBitPosition64( 0xBABE000000000000ULL ) returns 49.

For example, lowBitPosition64( 0x00000000BABE0000ULL ) returns 17.

For example, lowBitPosition64( 0x0000000000000000ULL) returns 64.

10. unsigned lowBitValue( unsigned n );

Returns the place value (contribution) of the lowest-order 1-bit in n.

For example, lowBitValue( 0x000ABC00U ) returns 1024, which is 2^10.

If there are no 1-bits, then the function should return 0.

11. unsigned long long lowBitValue64( unsigned long long nn );

64-bit version.

For example, lowBitValue64( 0x0600000000000000ULL ) returns 144115188075855872, which is 2^57.

If there are no 1-bits, then the function should return 0.

Here are the 12 prototypes, so you can just copy & paste them into your program:
void show( unsigned n );

void show64( unsigned long long nn );

unsigned f0( unsigned n );

unsigned long long f1( unsigned long long nn );

unsigned number1Bits( unsigned n );

unsigned number1Bits64( unsigned long long nn );

unsigned number0Bits( unsigned n );

unsigned number0Bits64( unsigned long long nn );

unsigned lowBitPosition( unsigned n );

unsigned lowBitPosition64( unsigned long long n );

unsigned lowBitValue( unsigned n );

unsigned long long lowBitValue64( unsigned long long n );

Reference no: EM132194673

Questions Cloud

A program to calculates a vehicles gas mileage : The program should ask the user to enter the number of gallons of gas the vehicle can hold and the number of miles it can be driven on a full tank.
Write a description of the selected dataset and project : ITECH1103- Big Data and Analytics - write a brief reflection about this project in terms of challenges, learning and contribution
Calculate the monthly cost of a house given selling price : Write a C++ program to calculate the monthly cost of a house given the selling price, annual rate of interest, and number of years for the loan.
Market for housing as a result : Suppose that consumers begin to believe that the price of housing will be lower next period. What will happen in the market for housing as a result
Write a c program that compiles and runs without errors : Write a C program that compiles and runs without errors or warnings. This program has a bunch of little bit-manipulation functions in it.
Compute how many seconds are in 20 years : Write a C# program to convert one billion seconds (1,000,000,000 seconds) into years, months, days, hours, minutes, and seconds, using visual studio.
Calculate the gross pay of a set of employees : Calculate the gross pay of a set of employees. For each employee the program should prompt the user to enter the clock number.
Find increase in temperature for a thermally insulated chunk : Radioactive decay of granite and other rocks in Earth's interior provides sufficient energy to keep the interior molten, to heat lava, and to provide warmth.
Calculate an average of several integers entered by the user : Calculate an average of several integers entered by the user. It first prompts the user to enter the number of integers she wants to average.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd