9

So I’m currently working on something and I have converted all decimal digits 0-9 into binary. But now I want to take say 6 in binary and increase its order of magnitude by base 10 (turning 6 into 60) without converting back to base 10. Is this possible and if so is there a way to do it with any number, X --> X0 ?

EDIT 1: sorry the first part of the question was super vague and I forgot to mention I’m trying to do this with logic gates.

David Richerby
  • 82,470
  • 26
  • 145
  • 239
user76675
  • 101
  • 1
  • 5

4 Answers4

48

I assume that the task is to compute $mul(10, a)= 10a$. You don't need to do multiplication. A single binary adder is enough since $$10a = 2^3a + 2a$$ meaning you add one-time left-shifted $a$ to 3-time left-shifted $a$. For general multiplication $mul(x,y)$ please see this article.

fade2black
  • 9,905
  • 2
  • 26
  • 36
11

Multiplying by 10 is the same as multiplying by $(1010)_2$. To multiply a binary number $x$ by 10, we thus just have to add $x0$ and $x000$. For example, $6 \times 10 = 60$ is implemented by $$ \begin{array}{ccccccc} &0&0&1&1&0&0 \\ +&1&1&0&0&0&0 \\\hline &1&1&1&1&0&0 \end{array} $$ The input is $(6)_{10} = (110)_2$, and the output is $(111100)_2 = (60)_{10}$.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514
6

Sure. You just compute $1010_\mathrm{b}\times 110_\mathrm{b}$ using the binary version of long multiplication (or some other algorithm). The nice thing about long multiplication in binary is that you never have to carry anything, except when you're adding things up at the end.

   1010
    110 x
  ------
    000
   110
  000
 110
--------
 111100
--------

and note that $11100_\mathrm{b}=60_\mathrm{d}$, as expected.

David Richerby
  • 82,470
  • 26
  • 145
  • 239
-2

Multiply by 8 (left shift 3) then add to it a multiply by two (left shift 1).