Subscribed unsubscribe Subscribe Subscribe

Takefumi Yamamura's blog

This blog is for my memorandum.

Takefumi Yamamura's b!og

This blog is for my memorandum


就活 bit manipulation


You are given two 32bit numbers n and m and two bit positions, i and j. Write a method to insert M into N such that M starts at bit j and ends at bit i.

how to solve

  • Clear the bits j through i in N
  • Shift M so that it lines up with bits j through i
  • Merge M and N


Remove all ads