有点小提琴 [英] Bit fiddling
问题描述
关于小提琴我几乎没有问题!!
1.快速将No乘以7的方法。
2.计算32中的设定位数没有循环就行了。
3.如果不使用%,/和 -
运算符,发现id为no可以被3整除,
>
I have got few questions on bit fiddling!!
1. Fast way of Multiplying a No by 7.
2. Counting no of set bits in a 32 bit no without looping.
3. finding id a no is divisible by 3 or not without using %, /, and -
operators,
推荐答案
2006年5月28日05:30:10 -0700," saurabhnsit2001"
< sa ***** ********@gmail.com>写道:
On 28 May 2006 05:30:10 -0700, "saurabhnsit2001"
<sa*************@gmail.com> wrote:
关于小提琴我几乎没有问题!!
I have got few questions on bit fiddling!!
我有几个关于家庭作业的问题有点小提琴
"I have got a few homework questions on bit fiddling"
saurabhnsit2001说:
saurabhnsit2001 said:
我对小小的摆弄有几个问题!!
1.快将No乘以7的方式。
n * = 7;
我对计算机的速度没有任何抱怨将
乘以7 - 它可以比我更快地运行。
2.在没有循环的情况下计算32位中的设置位数。
nbits = 0;
if(x& 0x1)++ nbits;
if(x& 0x2) ++ nbits;
if(x& 0x4)++ nbits;
if(x& 0x8)++ nbits;
if(x& 0x10)++ nbits;
if(x& 0x20)++ nbits;
if(x& 0x40)++ nbits;
if(x& 0x80)++ nbits;
if(x& 0x100)++ nbits;
if(x& 0x200)++ nbits;
if(x& 0x400)++ nbits;
if(x& 0x800)++ nbits;
if(x& 0x1000)++ nbits;
if(x& 0x2000)++ nbits;
if(x& 0x4000)++ nbits ;
if(x& 0x8000)++ nbits;
if(x& 0x10000)++ nbits;
if(x & 0x20000)++ nbits;
if(x& 0x40000)++ nbits;
if(x& 0x80000)++ nbits;
if(x& 0x100000)++ nbits;
if(x& 0x200000)++ nbits;
if(x& 0x400000)+ + nbits;
if(x& 0x800000)++ nbits;
if(x& 0x1000000)++ nbits;
if(x& 0x2000000)++ nbits;
if(x& 0x4000000)++ nbits;
if(x& 0x8000000)++ nbits;
if(x& 0x10000000)++ nbits;
if(x& 0x20000000)++ nbits;
if(x& 0x40000000)++ nbits ;
if(x& 0x80000000)++ nbits;
3.如果不使用%,/和 -
I have got few questions on bit fiddling!!
1. Fast way of Multiplying a No by 7.
n *= 7;
I have no complaints about the computer''s speed when it comes to multiplying
by 7 - it can do this way faster than I can.
2. Counting no of set bits in a 32 bit no without looping.
nbits = 0;
if(x & 0x1) ++nbits;
if(x & 0x2) ++nbits;
if(x & 0x4) ++nbits;
if(x & 0x8) ++nbits;
if(x & 0x10) ++nbits;
if(x & 0x20) ++nbits;
if(x & 0x40) ++nbits;
if(x & 0x80) ++nbits;
if(x & 0x100) ++nbits;
if(x & 0x200) ++nbits;
if(x & 0x400) ++nbits;
if(x & 0x800) ++nbits;
if(x & 0x1000) ++nbits;
if(x & 0x2000) ++nbits;
if(x & 0x4000) ++nbits;
if(x & 0x8000) ++nbits;
if(x & 0x10000) ++nbits;
if(x & 0x20000) ++nbits;
if(x & 0x40000) ++nbits;
if(x & 0x80000) ++nbits;
if(x & 0x100000) ++nbits;
if(x & 0x200000) ++nbits;
if(x & 0x400000) ++nbits;
if(x & 0x800000) ++nbits;
if(x & 0x1000000) ++nbits;
if(x & 0x2000000) ++nbits;
if(x & 0x4000000) ++nbits;
if(x & 0x8000000) ++nbits;
if(x & 0x10000000) ++nbits;
if(x & 0x20000000) ++nbits;
if(x & 0x40000000) ++nbits;
if(x & 0x80000000) ++nbits;
3. finding id a no is divisible by 3 or not without using %, /, and -
operators,
printf(%d可被3整除?\ n,n);
if(( ch = getchar())==''y''|| ch ==''Y'')
{
printf("%d可被整除3.\ n,n);
}
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上面的域名(但显然放弃了www)
printf("Is %d divisible by 3?\n", n);
if((ch = getchar()) == ''y'' || ch == ''Y'')
{
printf("%d is divisible by 3.\n", n);
}
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
saurabhnsit2001写道:
saurabhnsit2001 wrote:
关于小提琴,我几乎没有问题!
哇!真是太棒了!我几乎无法包含
我的热情!!!
1.快速将No乘以7..
这是一个技巧问题:没有快速的方法将
乘以7。乘以7表示幅度增加
,但幅度在
a快速下降。
2.计算32位中的设定位数没有循环。
另一个技巧问题:双重否定否则没有
意味着你必须*使用循环。如果您提交一个没有循环的解决方案
,您将收到一个不好的标记。
3.找不到id,否则可以被3除尽而不使用% ,/和 -
运营商,
I have got few questions on bit fiddling!!
Wow! That is so exciting!! I can hardly contain
my enthusiasm!!!
1. Fast way of Multiplying a No by 7.
This is a trick question: There is no fast way to
multiply by seven. Multiplying by seven implies an
increase in magnitude, but magnitude decreases during
a fast.
2. Counting no of set bits in a 32 bit no without looping.
Another trick question: The double negative "no without"
implies that you *must* use a loop. If you submit a solution
that does not have a loop, you will receive a bad mark.
3. finding id a no is divisible by 3 or not without using %, /, and -
operators,
您的教授必须非常喜欢技巧问题!在
这个案例中,你被问及弗洛伊德的意识分工
分为三个部分(注意可以被3整除):自我,id和
超我。这种模式在很大程度上被主流的精神病学家认可,但仍被教导为
学科的历史,并且仍然被外行人和一些边缘人士所信赖。 >
运营商。
如何找到你的身份证是C标准之外的问题。
-
Eric Sosman
es ***** @ acm-dot-org.inva 盖子
这篇关于有点小提琴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!