Write a function called b that looks for the occurrence of a specified pattern of bits inside an u . The function should take three arguments and should be called as shown:
b
The function searches the integer s , starting at the leftmost bit, to see if the rightmost n bits of p occur in s , If the pattern is found, have the function return the number of the bit at which the pattern begins, where the leftmost bit is bit number 0. If the pattern is not found, then have the function return -1. So, for example, the call
i
causes the b function to search the number 0xelf4( = 1110 0001 1111 0100 binary) for the occurrence of the three-bit pattern 0x5 (= 101 binary). The function returns 1 to indicate that the pattern was found in the source beginning with bit number 1 .
Make certain that the function makes no assumptions about the size of an i (see exercise 3 in this chapter).
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Programming in C
Additional Engineering Textbook Solutions
Modern Database Management
Problem Solving with C++ (10th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Starting Out with C++: Early Objects (9th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting out with Visual C# (4th Edition)
- Write a function that takes 4 Inter gets (num1, den1,num2,den2) as parameters which represent the rational numbers num1/den1, num2/den2 and returns the division of these two fractions. A/B ÷ C/D = A/B × D/C = AD/BC • den 1, den2, and num2 can not be zero. • use multiplication_rat function.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_forwardin JSarrow_forward
- 1. Fibonacci series can be created starting from 0 to the desired number. A function can be written for this operation and it can take two parameters: start and end. The default fırst parameter 0 is acceptable. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765..arrow_forwardDefine a function called digits that accepts two integer numbers m and n , and that displays m rows of n columns using the following pattern of digits. The first row starts with 1, the second row with 2, and so on until the 10th row starts with 0. Then the counter returns to 1 for the 11th row, then to 2 for the 12th, etc. For columns, the numbers are always incremented by 1 from the previous column, Except for the 9 that goes to 0. For example, the call digits(4, 7) must produce: 1234567234567834567894567890and the call numbers(12, 23) must produce: 123456789012345678901232345678901234567890123434567890123456789012345456789012345678901234565678901234567890123456767890123456789012345678789012345678901234567898901234567890123456789090123456789012345678901012345678901234567890121234567890123456789012323456789012345678901234Note that your function should not return anything, only display at the console.arrow_forwardWrite a function GCD( int A, int B ), when called from main function, returns the GCD (Greatest Common Divisor) of two numbers. Also get two numbers, X and Y from user and call this function to calculate GCD and show the result on Monitor. X and Y must be your reg# and 786, respectively. Note: GCD, Greatest Common Divisor: GCD of two numbers is the greatest number which can divide both the numbers. If the smaller of the two numbers can divide the larger number then the GCD is the smaller number. Else starting from 1 to (smaller / 2), check whether the current element divides both the numbers . If yes, then the highest of these devisors is the required GCD.arrow_forward
- 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.arrow_forwardWrite a function rightrot(x,n) that returns the value of the integer x rotatedto the right by n positions.arrow_forwardWrite a function print_times_table(factor, max_limit) that prints the times table for factor but with a twist. The table should start with 1 times the factor and keep printing lines until the product is greater than max_limit. To be clear, if the product is greater than the max_limit then that line should not be printed. Notes: You must use a while loop in your answer. You must NOT use any for loops or comprehensions in your answer. You can assume factor and max_limit will always be integers that are at least 1. You can assume that max_limit will always be greater than factor. For example: Test Result print_times_table(2, 10) 1x2=2 2x2=4 3x2=6 4x2=8 5x2=10 print_times_table(3, 20) 1x3=3 2x3=6 3x3=9 4x3=12 5x3=15 6x3=18arrow_forward
- Write a function named `pairs(a,b,c,d)` that takes four integers as its input and checks whether the sum of any two of these integers is equal to the sum of the other two. If so, the function RETURNs this sum. Otherwise, it RETURNs -1. For example, `pairs(1,2,3,4)` should return 5, because 1 + 4 = 2 + 3 = 5. Another example, `pairs(11,22,13,20)` should return 33, because 11 + 22 = 13 + 20 = 33. Another example, `pairs(1,2,3,5)` should return -1, because no such two pairs exist among these numbers. """ def pairs(a,b,c,d): # remove the following line to solve this question returnarrow_forwardDefine a function in loop_functions.py named count_collatz that takes a single paramater named a_0. This function takes a positive intenger a_0 and returns the minimum number of iterations required to find a term equal to 1. In other words, this function counts how many terms it takes to reach 1. Look at the list below for examples. You may use if statements but for and while loops are preferred.arrow_forwardWrite a function int solution(int N, int M, char CH) that accepts two integers (N and M) and one character CH. The function should return the product of two integers if a character (CH) is 'p' otherwise return their sum.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr