Programming in C
Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
bartleby

Videos

Textbook Question
Book Icon
Chapter 11, Problem 7E

Write a function called b to extract a specified set of bits. Have it take three arguments: the first an u , the second an integer starting bit number, and the third a bit count. Using the convention that bit numbering starts at 0 with the leftmost bit, extract the specified number of bits from the first argument and return the result. So the call

b

extracts the three leftmost bits from x. The call

b

extracts five bits starting with the fourth bit in from the left.

Blurred answer
Students have asked these similar questions
Write a function invert(x,p,n) that returns x with the n bits that begin atposition p inverted (i.e., 1 changed into 0 and vice versa), leaving the others unchanged.
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.
Q6. 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.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
CPP Function Parameters | Returning Values from Functions | C++ Video Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=WqukJuBnLQU;License: Standard YouTube License, CC-BY