Subject: Re: Base converter page
Date: Tue, 8 Jul 1997 21:27:21 -0400
From: Alexander Bogomolny

Hello, Leo:

Yes, of course, there is a way to convert decimals. One caveat though. You have to split the integer and decimal parts and convert them separately.

To convert the decimal part you have to multiply instead of dividing. Be careful with the limited precision arithmetic of JavaScript. I.e., beware that sooner or later you'll get meaningless digits.

To get a grasp on the algorithm take something simple like 1/16+1/8+1/2 = .6875 and keep multiplying by 2. Keep track of digits that pop up to the left of the decimal point:


Now conclude that in binary the decimal .6875 equals 0.1011. The same approach applies to other bases.

All the best,
Alexander Bogomolny

|Reply| |Up|

Copyright © 1996-2017 Alexander Bogomolny


Search by google: