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 9E
Program Plan Intro
To explain the reason why in two’s complement number system, x&(x-1) deletes the right most 1-bit in x. also use this observation to give faster version of bitcount.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
When multiplying an elliptic curve point P by a positive integer n, it can be done in O(log n) time by doubling an accumulator and adding P according to the bit pattern of n. For example, 6P can be expressed as ((0*2+P)*2+P)*2.
In the format shown above, show the sequence of doubles and adds, from left to right, needed to compute 11P. 11 in binary is 1011.
Autograder format: Begin with 0*2. After each +P close a parentheses (don't forget the opening parentheses) and after each *2 do not insert a close parentheses. Because of the order of operations these are the only parentheses needed. Do not insert any other parentheses or any spaces. Hint: there should be exactly three close parentheses.
Implement a shift and add multiplier in Verilog to multiply two 4 bit numbers. It should becapable of multiplying both positive and negative numbers. Negative numbers arerepresented in 2’sC representation.
Challenge: Use MIPS(MARS) to create a program that takes an 8-bit binary number and returns it as a binary-coded decimal (BCD).
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
- Implement the modular exponentiation (a.k.a. fast exponentiation) function mod_exp (b, n, m) to compute bn (mod m) more efficiently. (Hint: to read n bit-by-bit, use / and % operations repeatedly) a) Test your function for b = 3, n = 231 – 2, m = 231 – 1. b) Report the result and the time (in seconds) it takes to find the result. Q3. [30 pts] Modify your is_prime function to use the mod_exp (b, n, m) instead of the standard power operation (b**n % m). Rename it as is_prime2. Modify the mersenne (p) function to use is_prime2, and call it mersenne2. a) Use the modified function mersenne2 to print all the Mersenne primes Mp for p between 2 and 31 if possible, (with k = 3 in the is_prime function). Compare the results with the ones found in Q1. b) Gradually increase the range of p to find more Mersenne primes (say up to p = 101 if possible). What is the largest Mersenne prime you can achieve here? c) Extend the work in part (b) and find the maximum Mersenne prime you can get from this…arrow_forwardImplement the modular exponentiation (a.k.a. fast exponentiation)function mod_exp (b, n, m) to compute bn (mod m) more efficiently. (Hint: toread n bit-by-bit, use / and % operations repeatedly)a) Test your function for b = 3, n = 231 – 2, m = 231 – 1.b) Report the result and the time (in seconds) it takes to find the result. in pahtonarrow_forwardConsider the decimal number (-48.325). Write down binaryrepresentation of this number using the IEEE 745 single precision format. Clearly specify “Sign”, “Exponent” and “Mantissa” fields of the single precisionrepresentation.arrow_forward
- Answer only if you are 100% sure . Correct and detailed answer will be Upvoted else downvoted.arrow_forwardConsider an 8-bit variable that we want to use for storing real numbers. We decided touse 3 bits for storing the fractional part of the number. What are the minimum andmaximum values that we can store this way. What is the numerical error when storingvalue −7.6?arrow_forwardImplement the following function F(x,y,z) using a decoder. This function will return 1 if the value is divisible by Four otherwise it will return zero. asap pls.arrow_forward
- Implement integer division with rounding (not truncation) in MIPS assembly. This can be done by taking the remainder from the division, and dividing the original divisor by this number. If the new quotient is greater than or equal to 1, add 1 to the original quotient. Otherwise do not change the original quotient.arrow_forwardImplement code convertor Y=(X+4) mod 8 using decoder and encoder. Y and X are 3-bit numbers.arrow_forward: You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a methodto insert Minto N such that M starts at bit j and ends at bit i. You can assume that the bits j throughi have enough space to fit all of M. That is, if M = 10011, you can assume that there are at least 5bits between j and i. You would not, for example, have j = 3 and i = 2, because M could not fullyfit between bit 3 and bit 2.EXAMPLEInput: NOutput: NSOLUTION10000000000, M10001001100arrow_forward
- : You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a methodto insert Minto N such that M starts at bit j and ends at bit i. You can assume that the bits j throughi have enough space to fit all of M. That is, if M = 10011, you can assume that there are at least 5bits between j and i. You would not, for example, have j = 3 and i = 2, because M could not fullyfit between bit 3 and bit 2arrow_forward= = 2×2 and 6 = (a) A composite number is a positive integer that has at least one divisor other than 1 and itself. For example, 2 1×2 is not a composite number but 4 2 × 3 are composite numbers. A logic circuit has four binary input variables, A, B, C and D. The output Z of the logic circuit is 1 if the unsigned integer represented by the binary number ABCD is a composite number. Using variables A and B for the select inputs S1 and S0 of a 4-to-1 multiplexer, implement the logic function Z(A, B, C, D) using this multiplexor and other logic gates.arrow_forwardLet L={ w in(0 + 1)* 1 | w has even number of 1s}, i.e. L is the set of all bit strings with even number of 1s. Which one of the regular expression below represents L? (A) (0* 10* 1)* (B) 0* (10* 10* )* (C) 0* (10* 1* )* 0* (D) 0* 1(10* 1)* 10*arrow_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