C Programming Language
2nd Edition
ISBN: 9780131103627
Author: Brian W. Kernighan, Dennis M. Ritchie, Dennis Ritchie
Publisher: Prentice Hall
expand_more
expand_more
format_list_bulleted
Question
Chapter 2, Problem 6E
Program Plan Intro
- Initialize the header files and main() function.
- To define the function setbits(x, p, n, y) to return x with the n bits that begin at position p set to the right most n bits of y, leaving the other bits unchanged.
- Finally prints the position.
Summary Introduction- The program displays the x value after applying bitwise operators.
Program Description- The purpose of the program is to define the function setbits(x, p, n, y) to return x with the n bits that begin at position p set to the right most n bits of y, leaving the other bits unchanged.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a function setbits(x,p,n,y) that returns x with the n bits that begin at
position p set to the rightmost n bits of y, leaving the other bits unchanged.
Write a function setbits(x,p,n,y) that returns x with the n bits that begin atposition p set to the rightmost n bits of y, leaving the other bits unchanged.
Write a function int bitset(int x, int n) to set nth bit of x to 1, if its (n-1)th bit is 1. if n <1 or n >15, the function will return -1 to thecalling function
Chapter 2 Solutions
C Programming Language
Ch. 2 - Prob. 1ECh. 2 - Write a loop equivalent to the for loop above...Ch. 2 - Write the function htoi(s), which converts a suing...Ch. 2 - Write an alternate version of squeeze(s1,s2) that...Ch. 2 - Prob. 5ECh. 2 - Prob. 6ECh. 2 - Prob. 7ECh. 2 - Prob. 8ECh. 2 - Prob. 9ECh. 2 - Rewrite the function lower, which converts upper...
Knowledge Booster
Similar questions
- Write a C-function with two arguments (n and r) that has prototype: char clearbit(char k, char bits) The function clears (sets to 0) the bit number k (in the range of 0 to 7) in bits and returns the resulting value. For example, if k is 0x02 and bits is 0x07, the function would return bits with its k’th bit cleared, resulting in 0x03. It must not change other bits in bits. Hint: You may use any number of C-statements, but this task can be accomplished in as few as one!arrow_forwardIn C, write a function int setbit(int n, int i) to set the i^ᵗʰ bit of n if i^ᵗʰ bit is 0.arrow_forwardQ6. Write a function that takes an unsigned integer andreturns the number of '1' bits it has(also known as the Hamming weight).For example, the 32-bit integer '11' has binaryrepresentation 00000000000000000000000000001011,so the function should return 3.T(n)- O(k) : k is the number of 1s present in binary representation.NOTE: this complexity is better than O(log n).e.g. for n = 00010100000000000000000000000000only 2 iterations are required.Number of loops isequal to the number of 1s in the binary representation."""def count_ones_recur(n): Do it.arrow_forward
- C codingI have global variables called input_1 and output_1. If I want to modify bit 3 of output_1, such that it is equal to 1, only if bit 4 of input_1 is set. How do I do this? The other bits must be unaltered.arrow_forwardWrite a function to determine the number of bits you would need to flip to convertinteger A to integer B.EXAMPLEInput:Output:SOLUTION29 (or: 11101), 15 (or: 01111)2arrow_forwardIf you implement the function F(A,B,C,D)= Sum m (3,4,6,11,12,13,14) using a 8-1 MUX then which of the input position will be equal to D : a. I1 & I6 b. only I5 c. I2 & I6 & I7 d. Only I7 e. None of the choices f. I1 & I5arrow_forward
- Write a function that given an integer N returns the maximum possible value obtained by deleting one 5 digit from the decimal representation of N it is guaranteed that N will contain at least one 5 digitarrow_forwardWrite a function that returns the minimum number of swaps to convert the first binary string into the second. Examples minSwaps ("1100", "1001") → 1 minSwaps ("110011", "010111") → 1 minSwaps ("10011001", "01100110") → 4arrow_forwardProblem F. 73154. Trailing zeros Input file: Output file: Time limit: Memory limit: standard input standard output 1 second 256 megabytes In this problem, you are given 8-bit number r. Find the number of trailing zeros in its binary representation. Trailing zeros are the ones that we encounter until the first 1-bit if we traverse the binary representation from right to left. For example, the binary representation of the mumber 96 is 01100000. Number of 0-bits until the first 1-bit is 5 (considering that we traverse the binary representation from right to left). Input The first line of input contains a single number z – 8-bit number (1arrow_forwardThe Mux below implements the function F = 8 to 1 MUX ABC F Select one: O a. F = A'B'C + AB'C + ABC O b. F = A'B'C' + AB'C + AB'C + ABC' OC F=A'B'C' + A'BC' + A'BC + AB'C' + AB'C' O d. F= A'B'C + A'BC' + A'BC + ABCarrow_forward(a) Convert n to binary form, call it B. You may use the bin( ) function. (b) Split B into two “halves”, call them F and S, where if the length of B is odd, then include the extra digit in the first half. For example, if B = 101110, then the first half is F = 101 and the second half is S = 110. As another example, if B = 1100111, then the first half isF = 1100 and the second half is S = 111. (c) Convert F and S to decimal form, add one to each decimal form, and then return the product of these new values.arrow_forwardWrite a piece of code that copies the number inside AL (Only 8 bits) into whole edx, so that the value inside edx will be equal to the value inside the original AL. Example: Assume that Initially eax = 153BCF19h. When your code will end its running, edx will have Provide two different ways of accomplishing it. (a) (b)arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education