given a 32 bit number N and 2 numbers(A & B) that determine 2 different bit positions of N how do you make all the bits between A and B equal to another given integer k. given (A,B is in the range [0 to 31] and k<=2^(B-A+1) (so that k fits between B-A+1 bits). Give an O(1) solution for this
e.g if N=9 ( 1001) ,A=0 ,B=2,K=5(101 then the result should be 1101 (1.e 13)
(N|((2^(B-A+1)-1)<<A))&(k<<A)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment