Velocity Reviews > Funny old trick

# Funny old trick

CBFalconer
Guest
Posts: n/a

 07-07-2005
"Dik T. Winter" wrote:
>

.... snip ...
>
> Oh, it is quite clever. But there are so many people that discovered
> it independently. The whole point is that in C it makes no sense.
> Now, how about getting the decimals of an unsigned integer number
> below 1000 using only shifts and additions/subtractions...

Why limit yourself to values below 1000? See:

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the

Dik T. Winter
Guest
Posts: n/a

 07-07-2005
In article <(E-Mail Removed)> http://www.velocityreviews.com/forums/(E-Mail Removed) writes:
> "Dik T. Winter" wrote:

....
> > Oh, it is quite clever. But there are so many people that discovered
> > it independently. The whole point is that in C it makes no sense.
> > Now, how about getting the decimals of an unsigned integer number
> > below 1000 using only shifts and additions/subtractions...

>
> Why limit yourself to values below 1000? See:
>

O, I do it in 15 instructions, 9 shifts and 6 adds/subtracts, and
nothing conditional in between.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/

CBFalconer
Guest
Posts: n/a

 07-07-2005
"Dik T. Winter" wrote:
> (E-Mail Removed) writes:
>> "Dik T. Winter" wrote:

> ...
>>> Oh, it is quite clever. But there are so many people that discovered
>>> it independently. The whole point is that in C it makes no sense.
>>> Now, how about getting the decimals of an unsigned integer number
>>> below 1000 using only shifts and additions/subtractions...

>>
>> Why limit yourself to values below 1000? See:
>>

>
> O, I do it in 15 instructions, 9 shifts and 6 adds/subtracts, and
> nothing conditional in between.

Possibly of use in some heavily resource limited context, but I see
no real purpose for that size of value. I resurrected and
published that technique to handle bin-dec conversion of bignums,
where long drawn out divisions and modulos can be somewhat time and
memory consuming.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the

Dik T. Winter
Guest
Posts: n/a

 07-08-2005
In article <(E-Mail Removed)> (E-Mail Removed) writes:
> "Dik T. Winter" wrote:
> > (E-Mail Removed) writes:

....
> >> Why limit yourself to values below 1000? See:
> >>

> >
> > O, I do it in 15 instructions, 9 shifts and 6 adds/subtracts, and
> > nothing conditional in between.

>
> Possibly of use in some heavily resource limited context, but I see
> no real purpose for that size of value.

Indeed. Think CDC Cyber where the generation number of a permanent file
was at most 999. My comment was tongue-in-cheek. If you are not
resource limited, use the clearest way to express what you want.

> I resurrected and
> published that technique to handle bin-dec conversion of bignums,
> where long drawn out divisions and modulos can be somewhat time and
> memory consuming.

Yes, and in those circumstances shifts are also somewhat time and
memory consuming. I have written (back in the eighties) some of such
routines for a primality proving package (that should work for numbers
up to about 300 decimal digits). Reading in and printing out such
numbers is about the most insignificant part of the program, and I
did it quite naturally. If you are using bignums it makes no sense
to spend time to print a lot of the numbers you generate. Nobody will
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/

Michel Rouzic
Guest
Posts: n/a

 07-08-2005

BGreene wrote:
> I was not going to post this but my someone thought it was funny,
>
> Write the shortest c statement that will "exchange" two unsigned ints. in
> place.

ok, not sure I got it right... the point is to exchange two values
without using an intermediate variable? i'm not sure to get the point,
but this should do the trick... (provided that a+b isn't greater than
the greatest possible value)

a+=b;
b=a-b;
a=a-b;

...right?

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Lawrence D'Oliveiro NZ Computing 0 06-04-2011 07:06 AM DouhetSukd@gmail.com Python 1 09-14-2007 07:18 AM joevan Computer Support 0 06-29-2006 06:00 PM The Rev [MCT] MCSE 42 05-31-2005 10:42 PM lu Computer Support 6 01-14-2005 02:18 PM