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

  Which member functions are special member functions

Which member functions are special member functions, and what makes them special? What change in approach to storing 4000 double values would make the class.

  What is requirements definition

An aspect of the preferred process for almost all formal software development approaches is to do some design before coding. One of the plan artifacts you are asked to use in this course is a flow chart.

  How much bandwidth does the attacker consume

How much bandwidth does the attacker consume to send the necessary rate of DNS request packets for each of these three cases?

  Many acronyms did you recognize

Look in your local newspaper for an ad for a desktop computer. How many acronyms did you recognize? How many did you not recognize?

  Predict the future role of the communication technology you

select one 1 of the following topics in which you will base your responses in the form of a term papernetwork

  Which data structure is the optimum one

When lots of inserts & deletes are involved. When you have no clue about how big the list would grow.

  How many bytes of memory is this

Suppose that you discover that RAM addresses 000C0000 to 000C7FFF are reserved for a PC's video adapter in a 32-bit computer.

  Perform the affine mapping by computing the matrix-vector

Perform the affine mapping by computing the matrix-vector multiplication and addition.

  Discuss how data mining is being used to solve a problem

Discuss how data mining is being used to solve a problem (or to explore an opportunity)?

  Questionq1 assume that the ith operation on a data

questionq1 assume that the ith operation on a data structure takes thetaui time where ui is the number of units in the

  Separate following program into appropriate lexemes

Separate following program into appropriate lexemes

  Design a script that will allow the user to enter one

make a script that will allow the user to enter one of several choices from the command line.

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