20

奇数与偶数判断的两种方法-噗噗ink的博客

 3 years ago
source link: https://blog.51cto.com/14961688/2542480
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
首先,我们来讲最简单的奇偶数判定方法,即假设一个数为x,若x除以2余1,则为奇数;x除以2余0,则为偶数,具体如下:这是较为简单的一种判定方法,接下来,我们来看一下另一种判定方法:用按位与来判断数的奇偶性:按位与需将两个数转化为二进制的形式再逐个进行判断,通俗来讲即“两个数相同位数上的数字都为1时,结果才为1;若有一个数此位数上的数为0,那么结果上相同位数的数便为0.比如10&13,都化为

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK