![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Chapter 5 Bit Manipulation
文章平均质量分 77
u011846211
这个作者很懒,什么都没留下…
展开
-
5.1
Topic 5.1 You are given two 32-bit 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. You can assume that the bits j t翻译 2013-09-29 11:43:53 · 458 阅读 · 0 评论 -
5.2
Topic 5.2 Given a real number between 0 and 1(e.g.,0.72) that is passed in as a double, print the binary representation. If the number cannot be represented accurately in binary with at most 32 char翻译 2013-09-30 05:26:17 · 528 阅读 · 0 评论 -
5.3
Topic 5.3 Given a positive integer, print the next smallest and the next largest number that have the same number of 1 bits in their binary representation. 方法1:Brute Force Approach: count the numbe翻译 2013-10-01 17:02:18 · 460 阅读 · 0 评论 -
5.4
Topic 5.4 Explain what the following code does: ((n&(n-1)==0) 1) If A & B==0, A and B never have a 1 bit in the same place. 2) Subtract 1 from a number: ->If the last bit is 1, impossible翻译 2013-10-01 17:11:34 · 346 阅读 · 0 评论 -
5.5
Topic 5.5 Write a function to determine the number of bits required to convert interger A to interger B. 方法1:XOR represents a bit that is different between A and B. Then shift the XOR result. 改进:翻译 2013-10-03 13:23:57 · 444 阅读 · 0 评论 -
5.0
Topic 5.0 General Questions public static boolean getBit(int num, int i) { return ((num & (1 << i)) != 0); } public static int setBit(int num, int i) { return num | (1 << i); } publ翻译 2013-10-03 13:52:53 · 420 阅读 · 0 评论 -
5.6
Topic 5.6 Write a program to swap odd and even bits in an integer with as few instructionsn as possible. (e.g., bit 0 and bit 1 are swapped, bit 2 and bit 3 are swapped, and so on) 方法:Mask all odd bi翻译 2013-10-03 15:04:39 · 462 阅读 · 0 评论 -
5.7
Topic 5.7 An array A contains all the integers from 0 to n except for one number which is missing. In this problem, we cannot access an entire integer in A with a single operation. The elements of A a翻译 2013-10-04 06:09:31 · 859 阅读 · 0 评论 -
5.8
Topic 5.8 A monochrome screen is stored as a single array of bytes, allowing eight consecutive pixels to be stored in one byte. The screen has width w, where w is divisible by 8(that is, no byte wil翻译 2013-10-04 15:11:04 · 1018 阅读 · 0 评论