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:
"Emerson, Tom # El Monte" <[log in to unmask]>
Reply To:
Emerson, Tom # El Monte
Date:
Fri, 1 Dec 2000 14:34:14 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (57 lines)
As others have mentioned, the general case for converting from one base to
another is to find the "largest power of <the target base>" and subtract.
Binary data [which is what you're presenting here] is a "special case" --
special in the sense there is an easy way of doing this WITHOUT having to
resort finding the "largest power of 2 smaller than 'x'"

set aside a value of '1'
recursively DIVIDE your number by 2:
   if the remainder is 1, then the number "set aside" is one of the numbers
that makes up the "sum" you're after
   double the "set aside" number
repeat until the target number is zero.

Using your example (81) we have:

number (/2) rem  set aside   result set
----------------------------------------
  81    40   1      1        1,
  40    20   0      2        1,
  20    10   0      4        1,
  10     5   0      8        1,
   5     2   1     16        1, 16,
   2     1   0     32        1, 16,
   1     0   1     64        1, 16, 64,
   0     -   -     --        1, 16, 64.

> -----Original Message-----
> From: Porter, Allen H [mailto:[log in to unmask]]
> Sent: Friday, December 01, 2000 10:45 AM
> To: [log in to unmask]
> Subject: Math Help
>
>
> OK, I'm trying to figure this out but I cannot remember how
> to do the math
> behind it.
>
> If I have a series such as
> 1
> 2
> 4
> 8
> 16
> 32
> 64
> 128
>
> and I add any combination of these numbers together (4 + 16 =
> 20) the only
> way I can come up with the number 20 is by adding 4 and 16.
> Now how do I do
> this in reverse?  If I know the sum is 81, how do I determine that the
> numbers that make up this sum are 1 + 16 + 64?
>
> Thanks to anyone with the solution.
>

ATOM RSS1 RSS2