HP3000-L Archives

December 2000, Week 1

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Barry Lake <[log in to unmask]>
Reply To:
Barry Lake <[log in to unmask]>
Date:
Mon, 4 Dec 2000 09:30:31 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (50 lines)
At 11:03 AM -0400 12/4/00, Bob Comeau wrote:
>An expansion the simply elegant procedure easily displays the
>representation in the base chosen, up to 36:
...
>setvar base_rep  ""
>setvar base_digits "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
...
> if !base < 37
>  setvar base_rep "![str(base_digits,mod_val+1,1)]"+base_rep
> endif
...
>if !base < 37
> echo Written as !base_rep in base !base
>endif


Thanks Bob, that's a very nice addition to the script.
When I first wrote it and saw results like

  :powersum 4095,16,detail
  4095 = (15*1)+(15*16)+(15*256)

I thought, "hmmm, we almost have a base conversion utility here...", but I
didn't take it to the next step and actually implement it. I'm glad you did.

If we can tolerate a little potential confusion between upper and lower
case letters, then we could extend this a little further:

  setvar base_digits &
        "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
...
  if !base < len(base_digits)+1
     setvar...

Then we could do something like

  :powersum 8579781,62,detail
  8579781 = (35*1)+(61*62)+(61*3844)+(35*238328)
  Written as ZzzZ in base 62

Cheers,


Barry Lake                              [log in to unmask]
Allegro Consultants, Inc.               www.bogus.allegro.com
(408)252-2330
--------
Attempting to reduce spam influx.
Remove ".bogus" to create valid address.

ATOM RSS1 RSS2