有多少种方法在那里看到,如果一个数是偶数,哪一个是最快和最清晰? [英] how many ways are there to see if a number is even, and which one is the fastest and clearest?

查看:122
本文介绍了有多少种方法在那里看到,如果一个数是偶数,哪一个是最快和最清晰?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出任何数字,什么是判断它的即使是最好的方法是什么?你有多少方法能想到的,什么是最快的方法和清晰的方式?

解决方案

 布尔ISEVEN =((数量和放大器; 0×01)== 0)
 

现在的问题说:任何号码,所以人们既可以丢弃的花车或第一扩展它们备份到一个完整的价值首先他们以另一种方式处理,也许是 - 看出来溢出 - 即改变2.1〜21(乘以10并转换为int),然后测试。这可能是合理不过的假设,即通过提及任何数量的谁提出的问题的人实际上是指整数值。

given any number, what's the best way to determine it is even? how many methods can you think of, and what is the fastest way and clearest way?

解决方案

bool isEven = ((number & 0x01) == 0)

The question said "any number", so one could either discard floats or handle them in another manner, perhaps by first scaling them up to an integral value first - watching out for overflow - i.e. change 2.1 to 21 (multiply by 10 and convert to int) and then test. It may be reasonable to assume, however, that by mentioning "any number" the person who posed the question is actually referring to integral values.

这篇关于有多少种方法在那里看到,如果一个数是偶数,哪一个是最快和最清晰?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆