Convert from binary to quinary

5.1k Views Asked by At

How to convert a number from binary to quinary system without using decimal system ? It is possible ? I want to write a program who does it.

3

There are 3 best solutions below

0
On

See Donald E. Knuth: The Art of Computer Programming, Volume 2: Seminumerical Algorithms, third edition , chapter 4.4: Radix Conversion.

Knuth discusses four methods of conversion from base $B$ to $b$ using either $B$ or $b$ arithmetic.

  • Method 1a: Division by $B$ using radix-$b$ arithmetic

  • Method 1b: Multiplication by $b$ using radix-$B$ arithmetic

  • Method 2a: Multiplication by $B$ using radix-$b$ arithmetic

  • Method 2b: Division by $b$ using radix-$B$ arithmetic

Here neither $b$ nor $B$ must be $10$.

Note: You have probably access to arithmetic routines using base $b = 2$ (so you could avoid $b = 10$ as work arithmetic) and then radix convert to $B = 5$.

1
On

This question has already been treated in Computer Science Stackexchange.

See here: https://cs.stackexchange.com/questions/10318/the-math-behind-converting-from-any-base-to-any-base-without-going-through-base

1
On

In scanning a binary number (positive integer) from left to right, a $0$ bit doubles the previous value and a $1$ bit doubles the previous value and adds $1$.

So in left to right scanning, say $1011_2$, values are one ($1$), two ($10$), five ($101$), eleven ($1011)$. The value of this binary numeral is eleven. This idea of doubling or doubling and adding one can be done in any base.

For instance $10111_2$; converting to base $5$ (quinary) would go $1, 2, 10, 21, 43$. Answer $43_5$.

Or $1000101_2$ to base $5$ would go $1, 2, 4, 13, 32, 114, 234$ Answer: $234_5$.