max(a,b)
を実装する方法が議論されています。では、更に条件を厳しくして、「条件分岐も算術演算も使わずに」
max(a,b)
を実装することはできるでしょうか?も
ち
ろ
ん
可
能
で
す
回
答
例
は
以
下
に
あ
り
ま
す
なぜ、「もちろん」なのか。CPUは、ANDやOR、NOTのようなデジタルな論理回路から構成されています。であれば、当然、ビット演算(ビットシフトと
&
, |
, ^
)を使って、max(a, b)
を実装することも可能なわけです。こんな感じ。#include <stdio.h> #define BIT(n, pos) (((n) >> (pos)) & 1) static int mymax(int a, int b) { int islt = BIT(a, 31) & (BIT(b, 31) ^ 1); int iseq = BIT(a, 31) ^ BIT(b, 31) ^ 1; #define CHECK_BIT(pos) do { \ islt |= iseq & (BIT(a, pos) ^ 1) & BIT(b, pos); \ iseq &= BIT(a, pos) ^ BIT(b, pos) ^ 1; \ } while (0) CHECK_BIT(30); CHECK_BIT(29); CHECK_BIT(28); CHECK_BIT(27); CHECK_BIT(26); CHECK_BIT(25); CHECK_BIT(24); CHECK_BIT(23); CHECK_BIT(22); CHECK_BIT(21); CHECK_BIT(20); CHECK_BIT(19); CHECK_BIT(18); CHECK_BIT(17); CHECK_BIT(16); CHECK_BIT(15); CHECK_BIT(14); CHECK_BIT(13); CHECK_BIT(12); CHECK_BIT(11); CHECK_BIT(10); CHECK_BIT(9); CHECK_BIT(8); CHECK_BIT(7); CHECK_BIT(6); CHECK_BIT(5); CHECK_BIT(4); CHECK_BIT(3); CHECK_BIT(2); CHECK_BIT(1); CHECK_BIT(0); #undef CHECK_BIT /* extend flag to 32-bit mask */ islt <<= 31; islt >>= 31; return (a & (islt ^ 0xffffffff)) | (b & islt); } int main(int argc, char **argv) { int a, b; if (argc != 3) { fprintf(stderr, "Usage: %s a b\n", argv[0]); return 1; } if (sscanf(argv[1], "%d", &a) != 1) { fprintf(stderr, "%s is not a number\n", argv[1]); return 1; } if (sscanf(argv[2], "%d", &b) != 1) { fprintf(stderr, "%s is not a number\n", argv[2]); return 0; } printf("max(%d,%d) is %d\n", a, b, mymax(a, b)); return 0; }
Your blog was too good. i really appreciate with your blog.Thanks for sharing.
ReplyDeleteAsia Cup T20 2016 Schedule Time Table
Watch Asia Cup T20 Live Streaming Online & Broadcasting List
New Zealand Team Squad Players List
t20 world cup 2016 theme song
ReplyDeleteWow, Very nice and interesting post. Beautifully structured and very close to facts. I found myself lucky to go through it. Hope to have more post in future like this. Do you want to check Rio 2016 Summer Olympic? Vist followings:
ReplyDeleteRio 2016 Olympics Sailing Schedule
Rio 2016 Olympics Shooting Schedule
Rio 2016 Olympics Trampoline Gymnastics Schedule
Rio 2016 Olympic Track and Field Schedule
Rio Olympics 2016 Taekwondo Schedule
Rio 2016 Olympics Triathlon Schedule
Rio 2016 Olympic Tennis Schedule
Rio 2016 Olympic Soccer Schedule
Rio 2016 Olympics Table Tennis Schedule
Rio 2016 Olympic Rugby Schedule
Rio 2016 Olympic Swimming Schedule
Rio 2016 Summer Olympics Torch Relay
Rio 2016 Olympic Football Tournament
Rio 2016 Olympic Tickets Prices
Watch Rio Olympics 2016 Online
Rio Olympics 2016 Opening Ceremony Tickets
Rio 2016 Olympics Venue Map
List of 2016 Summer Olympics broadcasters
Daily Competition Schedule Rio 2016
I love how you still write and share about your day and experiences! You feel like such a real, nice, and humble person because of this!
ReplyDeletedark souls iii emoji keyboard diep.io slither.io
Live Boxing Stream 2016
ReplyDeleteWatch The Boxing Live
Watch Boxing Online Tv
Boxing Live Video Stream
Watch Over 4500 Plus HD Free Channel on Worldwide 2016 Crystal clear coverage is essential so you don’t miss any part of the action. The High Definition(HD) It’s is worldwide Channel coverage and no TV Streaming Online Boxing Streaming.
ReplyDeleteRio Olympics 2016 live
Live Rio Olympics 2016
Olympics 2016 live
Brazil Olympics live
Live Brazil Olympics
Rio Olympics 2016 streaming
Olympics rio stream live
michael kors outlet
ReplyDeleteoakley sunglasses
jordan 8s
kobe bryant shoes
cheap oakley sunglasses
giuseppe zanotti
lebron james shoes
coach outlet
louis vuitton
louis vuitton outlet
fitflops
toms shoes
air jordan 13
adidas ultra boost
michael kors outlet clearance
oakley sunglasses
coach factory outlet
true religion shorts
christian louboutin shoes
coach factory outlet
hermes bag
cheap ray ban sunglasses
ralph lauren sale
louis vuitton bags
coach outlet
designer handbags
ghd hair straighteners
toms outlet
ray ban sunglasses outlet
fitflops sale clearance
asics running shoes
christian louboutin sale
jordans for sale
cheap oakley sunglasses
louis vuitton outlet
adidas uk
cheap nfl jerseys
nike factory outlet
tiffany outlet
ralph lauren uk
20168.2wengdongdong
Memiliki daya tahan yang baik terhadap panas, karat dan goresan/gesekanPabrik besi hollow
ReplyDeleteToko besi Wf Baja
undangan pernikahan online
Supplier Besi Pipa Baja Schedule 40
Pabrik Plat Kapal Besi baja
Pabrik plat besi hitam
Pabrik besi beton psi Ulir Polos
Distributor besi hollow
Distributor besi hollow
Toko bondek
ReplyDeleteشركة نقل عفش بالرياض وجدة والدمام والخبر والجبيل اولقطيف والاحساء والرياض وجدة ومكة المدينة المنورة والخرج والطائف وخميس مشيط وبجدة افضل شركة نقل عفش بجدة نعرضها مجموعة الفا لنقل العفش بمكة والخرج والقصيم والطائف وتبوك وخميس مشيط ونجران وجيزان وبريدة والمدينة المنورة وينبع افضل شركات نقل الاثاث بالجبيل والطائف وخميس مشيط وبريدة وعنيزو وابها ونجران المدينة وينبع تبوك والقصيم الخرج حفر الباطن والظهران
شركة نقل عفش بجدة
شركة نقل عفش بالمدينة المنورة
شركة نقل اثاث بالرياض
شركة نقل عفش بالدمام
شركة نقل عفش بالطائف
شركة نقل عفش بمكة
ReplyDeleteشركة نقل عفش بينبع
شركة نقل عفش بالخرج
شركة نقل عفش ببريدة
شركة نقل عفش بخميس مشيط
شركة نقل عفش بينبع
ReplyDeleteنقل العفش والتخزين
شركة نقل عفش بالمدينة المنورة
شركة نقل عفش بالمدينة المنورة
This is very interesting, You’re a very skilled blogger. I have joined your feed and look forward to seeking more of your fantastic post. Also, I have shared your web site in my social networks!
ReplyDeleteRegards - www.office.com/setup
www.office.com/setup
Really very useful and Informative information are provided here. Thank you so much for writing keep up like this. Thanks
ReplyDeleteivanka trump hot pics
Escort Service in Mumbai
ReplyDeleteCall girls in Gurgaon
==========================
Gurgaon escorts
Bangalore escorts
Mumbai escorts
Gurgaon escorts
============================
Bangalore call girls
Gurgaon call girls
Gurgaon call girls
Mumbai call girls
==============================
Escort service in Gurgaon
Escort service in Gurgaon
Escort service in Mumbai
Escorts in Bangalore
Call girl in Gurgaon
call girls in lucknow
lucknow escorts service
call girls in guwahati
guwahati call girls
guwahati escorts
escorts in guwahati
=================================
escorts in jaipur
call girls in jaipur
escorts service in jaipur
jaipur call girls
jaipur call girls
escorts service in jaipur
I'm shakshi.I am working in India top most Escort serviceMumbai EScorts.If u want to join the all facility of escorts Bhubaneswar Escorts.pls call me & whatssap Puri Escorts
ReplyDeletevisit the sites. Cuttack Escorts or follow me.jaipur Escorts
ReplyDeleteHi friends ! I'm Archana Kumari. I like to have bed relationship with different persons rather than with a single man for the whole of life. Not only is this my notion , but also is this fact that the secret organs are made for enjoyment.
Please follow me on the links given bellow.
Mumbai Escorts
Mumbai Call girls
Escorts in Kolkata
Escorts in Kolkata
Escorts In kolkata
Jaipur Call girls
Kolkata Escorts
Call girl in Kolkata
House wife escorts in Kolkata
If you are interested in me and my ideology ,then you are invited to my bed. Thanks.
========================================================
selenium training in Bangalore
ReplyDeleteselenium courses in Bangalore
selenium training in Marathahalli
selenium training institute in bangalore
best web development training in Bangalore
web development course in bangalore
best web development training in Bangalore
web development training in Marathahalli
techbindhu
Hey Thanks for sharing this valuable information with us. I will come back to your site and keep sharing this information with us.
ReplyDeleteBest Regards - www.office.com/setup
www.office.com/setup
www.office.com/setup
Webroot.com/safe is a protection software solution that communicates with the cloud avoiding the hassle to manage the signature updates to deploy. for office setup visit office.com/setup
ReplyDelete
ReplyDeleteشركة نقل اثاث من الرياض الى الامارات
شركة شحن عفش من الرياض الي الامارات-دبي
شحن عفش من الرياض الي الامارات