{"id":962,"date":"2012-06-12T01:42:24","date_gmt":"2012-06-12T01:42:24","guid":{"rendered":"http:\/\/41j.com\/blog\/?p=962"},"modified":"2012-06-06T01:43:40","modified_gmt":"2012-06-06T01:43:40","slug":"c-multiply-without-multiply","status":"publish","type":"post","link":"https:\/\/41j.com\/blog\/2012\/06\/c-multiply-without-multiply\/","title":{"rendered":"C++ Multiply without multiply"},"content":{"rendered":"<p>A couple of ways for write multiply, without using multiply&#8230;<\/p>\n<p>int multiply(int value,int mul) {<\/p>\n<p>  int ret=0;<\/p>\n<p>  int mulabs = mul;<br \/>\n  if(mulabs &lt; 0) mulabs = 0 &#8211; mulabs;<\/p>\n<p>  for(int n=0;n&lt;mulabs;n++) {<br \/>\n    ret += value;<br \/>\n  }<\/p>\n<p>  if(mul &lt; 0) ret = 0-ret;<\/p>\n<p>  return ret;<br \/>\n}<\/p>\n<p>int multiply2(int value,int mul) {<\/p>\n<p> int total=0;<\/p>\n<p> for(int n=30;n&gt;=0;n&#8211;) {<\/p>\n<p>   if((mul &amp; (1 &lt;&lt; n)) &gt; 0) {<br \/>\n     total += value &lt;&lt; n;<br \/>\n   }<br \/>\n }<br \/>\n return total;<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A couple of ways for write multiply, without using multiply&#8230; int multiply(int value,int mul) { int ret=0; int mulabs = mul; if(mulabs &lt; 0) mulabs = 0 &#8211; mulabs; for(int n=0;n&lt;mulabs;n++) { ret += value; } if(mul &lt; 0) ret = 0-ret; return ret; } int multiply2(int value,int mul) { int total=0; for(int n=30;n&gt;=0;n&#8211;) { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-962","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1RRoU-fw","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/962","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/comments?post=962"}],"version-history":[{"count":1,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/962\/revisions"}],"predecessor-version":[{"id":963,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/962\/revisions\/963"}],"wp:attachment":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/media?parent=962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/categories?post=962"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/tags?post=962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}