最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

除以7而不使用除法运算符

SEO心得admin31浏览0评论
本文介绍了除以7而不使用除法运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

上个月,我出现在接受EA体育采访时,他们问了这个问题。 如果不使用数字,你如何将数字除以7分部操作员? 我做了一个减法并保留了一个计数器,保留了一个标签 减去了多少次。 后来,EA体育人告诉我,当然可以通过使用位操作符来更好地使用技术。 自7有一个二进制表示111,我的猜测是左移 3位的操作应该给出答案,但是我无法得到 工作。 有何意见?

解决方案

< kr ******** ***@gmail在留言中写道 新闻:11 ********************** @ p10g2000cwp.googlegr psps。 ..

上个月,我出现在EA体育的采访中,他们问了这个问题。 n。 如果不使用除法运算符,你如何将数字除以7? 我做了减法并保留了一个计数器保留了一个标签 减去了多少次。 后来,EA运动家伙告诉我当然有可能更好使用位运算符的技术。

最明显的方法是移动,比较和有条件地减去和b / b掩盖一个1的商数(非常像必要的汇编语言 在没有原生除法指令的处理器上。然而,这是非常低效的。。这涉及一些操作,但可能不是面试官正在寻找的那些 。 您可能会发布另一篇文章并交叉发布到sci.math同样。可能 来自那些人的一些好答案。

由于7有二进制表示111,我的猜测是左移 3位的操作应该给出答案,但是我无法得到 的工作。

我不确定你要去的方向是什么,除了死胡同。 我不是意识到你所建议的方向的一般方法 将与师合作。有一些很好的近似值(例如, 1/7 = 1/8 + 1/56,大约等于1/8 + 1/64),但我不是 意识到你建议的方向的确切方法。 - David T. Ashley(dt * @ e3ft) www.e3ft (咨询主页页面) www.dtashley (个人主页) gpl.e3ft (GPL出版物和项目)

kr ********** *@gmail 写道:

上个月我出现在接受EA体育采访的时候他们问了我这个问题。 如果不使用divi,你如何将数字除以7 sion运营商?

除以并截断为积分结果? 或 见如果一个数字可被7整除而没有余数?

kr *********** @ gmail 写道:

上个月我出现在接受EA sports和他们问了这个问题。 如果不使用除法运算符,你如何将数字除以7? 我做了一个减法并保留了一个计数器,保留了一个标签 减去了多少次。 后来,EA运动员告诉我那当然可以通过使用位运算符来更好地使用技术。 由于7具有二进制表示111,我的猜测是左移 3位的操作应该给出答案,但我无法得到 工作。 有何评论? (数量> 3)+ 1似乎有用吗?

Last month I appeared for an interview with EA sports and they asked me this question. How would you divide a number by 7 without using division operator ? I did by doing a subtraction and keeping a counter that kept a tab on how many times I subtracted. Later, the EA sport guy told me that of course there are can be better technique by using bit operator. Since 7 has a binary representation 111, my guess is that a left shift operation of 3 bits should give the answer, but I couldn''t get it to work. Any comments ?

解决方案

<kr***********@gmailwrote in message news:11**********************@p10g2000cwp.googlegr oups...

Last month I appeared for an interview with EA sports and they asked me this question. How would you divide a number by 7 without using division operator ? I did by doing a subtraction and keeping a counter that kept a tab on how many times I subtracted. Later, the EA sport guy told me that of course there are can be better technique by using bit operator.

The most obvious method is to shift, compare, and conditionally subtract and mask a 1 into the quotient (very much like the necessary assembly-language on a processor without a native division instruction). This is, however, very inefficient. This involves some bit operations, but may not be what the interviewer was looking for. You might make another post and cross-post to sci.math as well. There may be some good answers coming from those folks.

Since 7 has a binary representation 111, my guess is that a left shift operation of 3 bits should give the answer, but I couldn''t get it to work.

I''m not sure that the direction you''re going is anything except a dead end. I''m not aware of a general method in the direction you''ve suggested that will work with division. There are some good approximations (for example, 1/7 = 1/8 + 1/56 which is approximately equal to 1/8 + 1/64), but I''m not aware of an exact method in the direction you''re suggesting. -- David T. Ashley (dt*@e3ft) www.e3ft (Consulting Home Page) www.dtashley (Personal Home Page) gpl.e3ft (GPL Publications and Projects)

kr***********@gmail wrote:

Last month I appeared for an interview with EA sports and they asked me this question. How would you divide a number by 7 without using division operator ?

Divide by and truncate to integral result? or See if a number is divisible by 7 with no remainder?

kr***********@gmail wrote:

Last month I appeared for an interview with EA sports and they asked me this question. How would you divide a number by 7 without using division operator ? I did by doing a subtraction and keeping a counter that kept a tab on how many times I subtracted. Later, the EA sport guy told me that of course there are can be better technique by using bit operator. Since 7 has a binary representation 111, my guess is that a left shift operation of 3 bits should give the answer, but I couldn''t get it to work. Any comments ?

(num >3) + 1 seems to work?

发布评论

评论列表(0)

  1. 暂无评论