boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - a question about bits operation
相关主题
看一道面试题
bit manipulation 小题
Google 电话面试被拒
问一个bit operation的题目
贡献个uber电面面筋,攒人品
Google电话面试题目
问一道题
Search in a sorted, rotated list
贡献一道面试题
Given an array of N integers from range [0, N] and one is missing. Find the missing number.
相关话题的讨论汇总
话题: bits话题: 0xcccccccc话题: 0xf0f0f0f0话题: 0xff00ff00话题: 0x00ff00ff
进入JobHunting版参与讨论
1 (共1页)
c***2
发帖数: 838
1
Given a 32-bit integer, write a function to return the number by mirroring
all bits.
s*****n
发帖数: 5488
2
don't understand the english.

【在 c***2 的大作中提到】
: Given a 32-bit integer, write a function to return the number by mirroring
: all bits.

c***2
发帖数: 838
3
if you put .....101011 before a mirror, what do you see? :-)
....101011 |(mirror) = 110101......
bit 0 becomes bit 31
bit 1 becomes bit 30
and so on...
r*********s
发帖数: 2157
4
x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
return((x >> 16) | (x << 16));
K******g
发帖数: 1870
5
不就是倒过来吗?
#define REVERSE((x)) (x)=(((x)&0xFFFF0000)>>16|((x)&0x0000FFFF)<<16) \
(x)=(((x)&0xFF00FF00)>>8|((x)&0x00FF00FF)<<8) \
(x)=(((x)&0xF0F0F0F0)>>4|((x)&0x0F0F0F0F)<<4) \
(x)=(((x)&0xCCCCCCCC)>>2|((x)&0x33333333)<<2) \
(x)=(((x)&0xAAAAAAAA)>>1|((x)&0x55555555)<<1)

【在 c***2 的大作中提到】
: Given a 32-bit integer, write a function to return the number by mirroring
: all bits.

c***2
发帖数: 838
6
yes, here's what I do in straightforward way:
int mirror_bits( int num)
{
int tmp=0;
int i=0;
while(num>(1< if((1< tmp |= 1<<(31-i);
}
i++;
}

return tmp;
}
c***2
发帖数: 838
7
you are right. can you please make your codes compile and run?

【在 K******g 的大作中提到】
: 不就是倒过来吗?
: #define REVERSE((x)) (x)=(((x)&0xFFFF0000)>>16|((x)&0x0000FFFF)<<16) \
: (x)=(((x)&0xFF00FF00)>>8|((x)&0x00FF00FF)<<8) \
: (x)=(((x)&0xF0F0F0F0)>>4|((x)&0x0F0F0F0F)<<4) \
: (x)=(((x)&0xCCCCCCCC)>>2|((x)&0x33333333)<<2) \
: (x)=(((x)&0xAAAAAAAA)>>1|((x)&0x55555555)<<1)

c***2
发帖数: 838
8
good one.

【在 r*********s 的大作中提到】
: x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
: x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
: x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
: x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
: return((x >> 16) | (x << 16));

1 (共1页)
进入JobHunting版参与讨论
相关主题
Given an array of N integers from range [0, N] and one is missing. Find the missing number.
问一道面试题目
这道题怎么做的?
请问如何安全地reverse 一个integer
请教一道Leetcode 题, 多谢
请教leetcode一道题
google 首轮面世汇报
再来一道简单的bit运算题
请教一个数论的问题
题目来啦
相关话题的讨论汇总
话题: bits话题: 0xcccccccc话题: 0xf0f0f0f0话题: 0xff00ff00话题: 0x00ff00ff