惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
G
Google Developers Blog
B
Blog
Engineering at Meta
Engineering at Meta
阮一峰的网络日志
阮一峰的网络日志
The Register - Security
The Register - Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 叶小钗
The Cloudflare Blog
The Hacker News
The Hacker News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
雷峰网
雷峰网
F
Fortinet All Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
A
About on SuperTechFans
量子位
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
H
Help Net Security
Help Net Security
Help Net Security
P
Palo Alto Networks Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Troy Hunt's Blog
W
WeLiveSecurity
V
Vulnerabilities – Threatpost
T
The Exploit Database - CXSecurity.com
Know Your Adversary
Know Your Adversary
Apple Machine Learning Research
Apple Machine Learning Research
Scott Helme
Scott Helme
N
News | PayPal Newsroom
AWS News Blog
AWS News Blog
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
腾讯CDC
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
TaoSecurity Blog
TaoSecurity Blog
GbyAI
GbyAI
Y
Y Combinator Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Docker

博客园 - 戴晶晶

Ubuntu 服务器采用Systemed管理Tomcat服务自动启动 指尖刺激 人生、成长、成功 事业生涯力戒“浮躁” 又“不务正业”的花了近一天的时间看了本别人推荐的书《我的成功可以复制》 [转]80后的家装--超级爱不释手 打印设置 郁闷 还是这里速度比较快,呵呵 这两天做梦都能梦见胃疼 软件需求分析阶段 人生规划 audio codec ??? 看起来简单, 实际上复杂 [转] 读“进行中开火” 招聘、面试技巧 [转] 软件成功12法则 [转] 吃了就想睡,呵呵 IP多播技术及其编程 [转] 今天又学了一招 如果我新接一个做到一半的项目,或者需要二次开发的项目我希望了解的内容有哪些? G.729音频编码率 抽空做了一个测试网速的咚咚 洗个澡、搓个背,舒坦! 下乡去了,呵呵
不用判断性语句实现求两数中最大数的函数
戴晶晶 · 2004-06-29 · via 博客园 - 戴晶晶

不用判断性语句实现求两数中最大数的函数

// 算法
inline int signof(int i)
{
   return unsigned(i) >> (sizeof(int)*8-1);
}

int max(int a, int b)
{
    int p[2];
    p[0]=a;
    p[1]=b;
    return p[signof(a-b)];
}

/*解释
a & b 比较大小有三种情况
a > b (这种情况下 a-b>0)
a < b (这种情况下 a-b<0)
a = b (不用说了,再说就废话连篇了)

计算机编码中(int类型的)
>0 = 0XXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
<0 = 1XXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

这样就有一个特点,右移31bit就会出现 0,1

如果为 0 则 a 大
如果为 1 则 b 大
*/

posted @ 2004-06-29 10:35  戴晶晶  阅读(289)  评论(0)    收藏  举报