TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Roger Scudder
from: Jasen Betts
date: 2004-06-08 08:41:46
subject: RE: [C] C Puzzles

Hi Roger.

06-Jun-04 17:18:58, Roger Scudder wrote to All


 RS> From: "Roger Scudder" 

 RS> On Saturday, June 05, 2004 2:11 PM, Darin McBride wrote:

 >> > > > 4. Multiply x by 7 without using multiplication
(*) operator.
 >> > > > > x = (x  > I like that
Roger.  I had done this
 >> less clever solution: > > x = (x << 2) +( x << 1) +  x;

 >> Less clever, but more correct.  Less likely to overflow the
 >> variable

AFAICT x<<3-x will give the same result as x*7 even when x<<3 does
overflow, because the -x will overflow in the opposite direction :)

 -=> Bye <=-

---
* Origin: I smell a rat. Did you bake it or fry it? (3:640/1042)
SEEN-BY: 633/267 270
@PATH: 640/1042 531 954 774/605 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.