Re: Converting base 255->256 and vice versa
From: Thad Smith (thadsmith_at_acm.org)
Date: 01/08/04
- Next message: OmegaZero2003: "Re: What IS Intelligence"
- Previous message: Graham Lewis: "Re: Converting base 255->256 and vice versa"
- In reply to: Graham Lewis: "Converting base 255->256 and vice versa"
- Next in thread: Willem: "Re: Converting base 255->256 and vice versa"
- Reply: Willem: "Re: Converting base 255->256 and vice versa"
- Reply: Willem: "Re: Converting base 255->256 and vice versa"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 08 Jan 2004 10:43:58 -0700
Graham Lewis wrote:
> I'm trying to convert a 32 byte wide, base 255 number to base 256.
A easy way to convert is to build up the number an input digit at a
time, starting with the msd.
As an example, assume that the input digits are a, b, c, ..., base 255.
x = a
x = x*255 + b
x = x*255 + c
...
Of course, you need to use multiple precision arithmetic for x. Note
that you only need to be able to multiply by 255 and add a single digit.
Use the normal hand multiply technique for multiplying by 255,
multiplying each digit of the multiplicand with the multiplier (255),
saving the lower digit of the product and carrying the higher digit.
There is also a shortcut for this particular base in which you multiply
by 256 then subtract the original number, in which you avoid the
multiply operation (useful for low end micros without a multiply).
Adding a single digit is just like hand addition, where you add digits
together, keeping the lower order digit and carrying the high order
digit to the next summation.
Thad
- Next message: OmegaZero2003: "Re: What IS Intelligence"
- Previous message: Graham Lewis: "Re: Converting base 255->256 and vice versa"
- In reply to: Graham Lewis: "Converting base 255->256 and vice versa"
- Next in thread: Willem: "Re: Converting base 255->256 and vice versa"
- Reply: Willem: "Re: Converting base 255->256 and vice versa"
- Reply: Willem: "Re: Converting base 255->256 and vice versa"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|