由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 看一道面试题
相关主题
贡献一道面试题问个面试题
问一个关于xor的题请教一个面试题
a question about bits operationGoogle 面试题 一道
bit manipulation 小题问一个面试题
FLG面试题,压缩整数 (转载)问几道面试题
大家看看这几道亚麻面试题怎么做?一道面试题
看到一个c的面试题,求教。彭博 面试题
面试题讨论:integer to English。 例:3542 --> Three Five Four TwoGoogle电话面试题目
相关话题的讨论汇总
话题: unsigned话题: given话题: ra话题: int话题: bit
进入JobHunting版参与讨论
1 (共1页)
l*******r
发帖数: 511
1
given a 32 bit number N and 2 numbers(A & B) that determine 2 different bit
pos
itions 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
th
is
e.g if N=9 ( 1001) ,A=0 ,B=2,K=5(101 then the result should be 1101 (1.e 13)
这个题是什么意思啊?
a**********s
发帖数: 588
2
If that answer is something like:
(k << A) | (((-1) << (B+1)) & N) | ((unsigned(-1) >> (32-A)) & N)
Then this is a crap 面试题...
f**e
发帖数: 1269
3
hoho... 不错,读algorithmics的帖子总是痛并快乐着……
位操作读起来太痛苦了,我一看你写的跟我不一样就懒得读了。我写的是
if (k^ ((n<<(31-B)) >>> (31-B + A-1)) == 0)
then return true

【在 a**********s 的大作中提到】
: If that answer is something like:
: (k << A) | (((-1) << (B+1)) & N) | ((unsigned(-1) >> (32-A)) & N)
: Then this is a crap 面试题...

l*******r
发帖数: 511
4
I don't know the answer but what is given in the prob?

【在 a**********s 的大作中提到】
: If that answer is something like:
: (k << A) | (((-1) << (B+1)) & N) | ((unsigned(-1) >> (32-A)) & N)
: Then this is a crap 面试题...

f**e
发帖数: 1269
5
就是说你有个数n用32位表达
其中a和b分别指向两个不一样的bit,比如说a指向bit 3, b指向bit 8。
问a和b之间的binary串的值是否等于k?

【在 a**********s 的大作中提到】
: If that answer is something like:
: (k << A) | (((-1) << (B+1)) & N) | ((unsigned(-1) >> (32-A)) & N)
: Then this is a crap 面试题...

a**********s
发帖数: 588
6
不是, 题目要求你把k填到从A到B之间的二进制位

【在 f**e 的大作中提到】
: 就是说你有个数n用32位表达
: 其中a和b分别指向两个不一样的bit,比如说a指向bit 3, b指向bit 8。
: 问a和b之间的binary串的值是否等于k?

a**********s
发帖数: 588
7
I wrote a short program for OP to understand:
char buffer[65];
unsigned int N = 0x8fde27e3;
unsigned int A = 3, B = 17, K = 0x7893;
printf("N = %s....\n", itoa(N, buffer, 2));
printf("K = ..............%s ....\n", itoa(K, buffer, 2));
unsigned int Rk = (K << A);
unsigned int Ra = ((unsigned(-1) >> (32-A)) & N);
unsigned int Rb = ((-1 << (B+1)) & N);
unsigned int R = Ra | Rk | Rb;
printf("Ra = %s....\n", itoa(Ra, buffer, 2));
printf("Rk = %s....\n",
f**e
发帖数: 1269
8
a....我看错了。
那得重写
N ^ (((N<<(31-B))>>>(31 + A - B))<
【在 a**********s 的大作中提到】
: 不是, 题目要求你把k填到从A到B之间的二进制位
1 (共1页)
进入JobHunting版参与讨论
相关主题
Google电话面试题目FLG面试题,压缩整数 (转载)
问一道题大家看看这几道亚麻面试题怎么做?
补 ms onsite 面筋看到一个c的面试题,求教。
Search in a sorted, rotated list面试题讨论:integer to English。 例:3542 --> Three Five Four Two
贡献一道面试题问个面试题
问一个关于xor的题请教一个面试题
a question about bits operationGoogle 面试题 一道
bit manipulation 小题问一个面试题
相关话题的讨论汇总
话题: unsigned话题: given话题: ra话题: int话题: bit