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
Program Plan-
- 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 the function int count101(int n) that counts the number of occurrences of the bit pattern 101 in n.
It should return the final count. Variable n is 32 bits. Example: Suppose n is just 8 bits, say n=11010101, then the function would return 3.
In C, write a function int setbit(int n, int i) to set the i^ᵗʰ bit of n if i^ᵗʰ bit is 0.
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 digit
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
- This exercise is to write a Decimal to Hex function using BYTE operations. You can use a List, Dictionary or Tuple for your Hex_Map as shown below, but it's not necessary to use one. It is necessary to use Byte operations to convert the decimal to hex. The bitwise operations are also available as __dunders__. Write a function to convert a integer to hexidecimal. Do not use the Python hex function (i.e. hexnumber = hex(number)) to convert the number, instead write your own unique version (i.e. MYHEX: hexnumber = MYHEX(number)). Your function should not use any Python functions like hex, dec, oct, bin or any other Python functions or modules. Functions, like Python ORD, can be used to convert a string to a integer. The input number range is 0 to 1024. def MYHEX(number): hex_map = {10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'} result = '' while number: digit = number % 16 if digit > 9: result = hex_map[digit] + result else:…arrow_forwardWrite a C language function named more_ones that takes a uint32_t parameter as input and returns an int result. The returned result should be 1 if there are strincly more 1 bits in the input than 0 bits, and 0 otherwise. So, more_ones(0) should return 0 while more_ones(0x0ffffff) should return 1. You must use bitwise operations to solve this problem and may not use any library functions to help.arrow_forwardWrite a function that takes the number n, which reverses the binary representation of that number, and then returns the new number from the returned binary. Examples BinaryInteger (10) - 5 // 10 = 1010 -> 0101 = 5 BinaryInteger (12) → 3 // 12 = 1100 -> 0011 = 3 BinaryInteger (25) → 19 // 25 = 11001 -> 10011 = 19 BinaryInteger (45) → 45 // 45 = 101101 -> 101101 = 45arrow_forward
- binaryAddition functionThis function takes two static arrays, bit pattern length, and a third static array as its arguments. The function must populate the third array with the binary sum of the first two arrays in the given bit pattern length. Assume the first two arrays are populated with binary bits in the given bit pattern length. Moreover assume that all the arguments are valid.arrow_forwardBuild a _lengOfSt function in MIPS, that takes an argument in $a1 which is the address of a null-terminated string, returning the length of the given string (number of characters excluding the null-character) in $v0.arrow_forwardWrite a function that keeps computing the sum of the digits of x^n, until there is only one digit left. For example, sumOfDigits(2,5) returns 5, because 2 ^ 5 = 32 = 3 + 2 = 5 Another example, sumOfDigits(2,8) returns 4, because 2 ^ 8 = 128 = 1 + 2 + 8 = 13 = 1 + 3 = 4arrow_forward
- Write a function FlipBit with two parameters to manipulate a target bit. The first parameter contains an unsigned byte of data, and the second parameter is an integer value that specifies which bit to toggle inside the first parameter (e.g., bit #0 is the least significant bit on the far right, bit #1 is to the left of that, bit #2 to the left of that, etc.). If the target bit is set it should be cleared, and if it is cleared it should be set. The function should return the updated value to the caller. For example, this would flip bit number 3 in first argument: myByte FlipBit (myByte, 3); NOTE: All you have to write is the FlipBit function, nothing else.arrow_forwardNeed SML help for coding. I need to define a function called decimal (val decimal = fn: string -> int) that takes a bit string corresponding to an integer and returns the decimal value of that integer. For example, decimal "10001" returns 17, decimal "001101" returns 13.arrow_forwardWrite a function that takes one input arr1, an array of 3 numbers. It should return one output, smallest a scalar double. smallest should be the index number of the lowest number in arr1. Assume that all 3 numbers are different. Do not use min or max to write this functionarrow_forward
- Please explain your solutionarrow_forward* Write a function in python to clear the rightmost set bit of a number.arrow_forwardWrite the pseudo code and the python code for a function that will accept a dna sequence, start position, stop position: The function should: (a) Return the exon. (b) Set a default value for the stop position to be the length of the sequence (c) Ensure that the number of nucleotides in the coding exon is a multiple of 3arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_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