Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2] 3

Author Topic: Binary Multiplication  (Read 5967 times)

Cheddarius

  • Bay Watcher
  • Hrm.
    • View Profile
Re: Binary Multiplication
« Reply #15 on: February 12, 2010, 01:39:49 am »

Yeah, normally you carry over the normal way, right? By putting a little "1" above the next digit? But I can't do that on the forum, only on paper. So I improvised.
Logged

winner

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #16 on: February 12, 2010, 02:14:20 am »

Yeah, normally you carry over the normal way, right? By putting a little "1" above the next digit? But I can't do that on the forum, only on paper. So I improvised.
and some algorithms use that method.
Logged
The great game of Warlocks!

eerr

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #17 on: February 12, 2010, 04:12:20 am »

Yeah, I've decided that this is one of those useless skills that you only use for showing off.
Hah showing off.

Tell that to the people who write assemblers, and design microchips.

A strong foundation in a subject can sometimes help you elsewhere.
That is to say, this crap is good to learn if you want to be smart.
Logged

Armok

  • Bay Watcher
  • God of Blood
    • View Profile
Re: Binary Multiplication
« Reply #18 on: February 12, 2010, 03:41:22 pm »

You actualy don't really usualy use this stuff when programing in assembly (there are some special aplications for it I guss, but generaly you don't need it), multiplication is atomic in any proccesor I've heard of. When designing chips you do use it a lot however, as well as in microprograming I'd imagine.
Logged
So says Armok, God of blood.
Sszsszssoo...
Sszsszssaaayysss...
III...

G-Flex

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #19 on: February 12, 2010, 08:07:38 pm »

Knowing how binary multiplication works is still useful.

I remember seeing "<< 1" used instead of "* 2" in some C++ code before.
Logged
There are 2 types of people in the world: Those who understand hexadecimal, and those who don't.
Visit the #Bay12Games IRC channel on NewNet
== Human Renovation: My Deus Ex mod/fan patch (v1.30, updated 5/31/2012) ==

eerr

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #20 on: February 12, 2010, 09:52:59 pm »

You actualy don't really usualy use this stuff when programing in assembly (there are some special aplications for it I guss, but generaly you don't need it), multiplication is atomic in any proccesor I've heard of. When designing chips you do use it a lot however, as well as in microprograming I'd imagine.
Your spam of impossibility is broken!

You have posted something that is neither impossible, nor does it obscure your purpose..
Logged

G-Flex

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #21 on: February 13, 2010, 01:17:43 pm »

... What?

I don't think he said that anything was impossible.
Logged
There are 2 types of people in the world: Those who understand hexadecimal, and those who don't.
Visit the #Bay12Games IRC channel on NewNet
== Human Renovation: My Deus Ex mod/fan patch (v1.30, updated 5/31/2012) ==

chaoticag

  • Bay Watcher
  • All Natural Pengbean
    • View Profile
Re: Binary Multiplication
« Reply #22 on: February 13, 2010, 01:41:23 pm »

Nah, he had a few odd ideas a while back. Something to do with numbers and the universe where the math used was a little wonkey.

I have no idea what it was about, since if it isn't explainable in less than a minute, then it isn't worth listening to, and the less that is said about it the better.
Logged

sproingie

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #23 on: February 13, 2010, 11:49:25 pm »

multiplication is atomic in any proccesor I've heard of.

Atmel AVRs take two cycles for multiplication.  Those things are hardly obscure.  Besides, "atomic" has a very different meaning -- even plain old incrementing isn't normally atomic.
Logged
Toady is the man who Peter Molyneux wishes he was

Quote from: ToadyOne
dragon pus was like creamy gold. Infect and collect!

eerr

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #24 on: February 16, 2010, 05:17:55 pm »

... What?

I don't think he said that anything was impossible.
Not that time, but like every other time before this for at least half a year...

Armok always mentioned something impossible(for varying reasons) near the end of his posts.
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: Binary Multiplication
« Reply #25 on: February 16, 2010, 07:02:12 pm »

Do you really want to know how to do binary multiplication?

We have two 32 bit numbers we want to multiply, a and b.

Doing 32 bit multiplication in a single step is very difficult. It has 64 bit input and 64 bit output . We can simulate this by cutting the inputs in half.

The answer is:
 a0*b0
+a1*b0<<8
+a0*b1<<8
+a1*b1<<16.

Doing 16 bit multiplication in a single step is difficult. It has 32 bits of input and 32 bits of output. Good thing we can split it in half.

The answer is:
 a0*b0
+a1*b0<<4
+a0*b1<<4
+a1*b1<<8.

Doing 8 bit multiplication in a sing step is hard...

The answer is:
 a0*b0
+a1*b0<<2
+a0*b1<<2
+a1*b1<<4.

Doing 4 bit multiplication in a sing step is reasonable, but lets continue the trend...

The answer is:
 a0*b0
+a1*b0<<1
+a0*b1<<1
+a1*b1<<2.


Doing 2 bit multiplication in a sing step is easy...
We will name the digits of the first input number a and b. We will name the digits of the second input number x and y. We will name the digits of the output number A, B, C, D. All names are from highest order to lowest.
Code: [Select]
  xy   xy   xy   xy
ab        00   01   10   11
00 0000 0000 0000 0000
01 0000 0001 0010 0011
10 0000 0010 0100 0110
11 0000 0011 0110 1001
Now we make our rules.
The easiest rule is for A. It is all inputs and'd together.
A = abxy

B is a little trickier, as there are more options. including nots (!) and or's.
B =  a!b x!y
B =  a b x!y
B =  a!b x y
The b!b in the first two rules cancel.
B =  a   x!y
B =  a   x y
The y!y cancel.
B =  ax

D is pretty simple as well.
D = !a b!x y
D = !a b x y
D =  a b!x y
D =  a b x y
Cancel x!x in the first 2 and the last 2.
D = !a b   y
D =  a b   y
Cancel a!a.
D =  by

C is even worse.
C =  a!b!x y
C =  a b!x y
C = !a b x!y
C =  a b x!y
C = !a b x y
C =  a!b x y
The a!a in the first two rules cancel.
C =    b!x y
C = !a b x!y
C =  a b x!y
C = !a b x y
C =  a!b x y
The a!a in the 2nd and 3rd rule cancel.
C =    b!x y
C =    b x!y
C = !a b x y
C =  a!b x y
Now I add an xor (+) to keep simplifying the first two rules.
C =    b(x+y)
C = !a b x y
C =  a!b x y
Apply xor again to the last two.
C =    b(x+y)
C = (a+b)x y
Combine with an or (|).
C = b(x+y)|(a+b)xy

Congradulations, we just turned 2 bit multiplication into 3 simple rules and one moderate rule in binary algebra.
A = abxy
B =  ax
C =  b(x+y)|(a+b)xy
D =  by

You could scale this process up to 4 bit, and 8 bit relatively easilly. But to reduce 16, 32 or 64 bit multiplication to rules like this? No human can do it and even machine designs for the higher numbers are likely to complex to be useful. Using 8 bit multipliers, you need 16 multiplications and 15 shifts and 15 adds to multiply 2 32 bit numbers. You could arrange 20 such 8 bit multiplers with 16 in the first stage and 4 in the second stage with output fed from the first stage into second stage input and get that multiplication for a 32 bit number done in only 2 clock ticks.


Note that if you were to be implementing this in silicon, you would use additional algebra to turn everything into NAND operations because NAND ops because NAND gates are cheap.
« Last Edit: February 16, 2010, 07:10:04 pm by Nadaka »
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Vector

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #26 on: February 16, 2010, 08:36:30 pm »

Man, why bother with all the applied computational stuff here?  Just do it the abstract way, with arbitrary long bitstrings.
Logged
"The question of the usefulness of poetry arises only in periods of its decline, while in periods of its flowering, no one doubts its total uselessness." - Boris Pasternak

nonbinary/genderfluid/genderqueer renegade mathematician and mafia subforum limpet. please avoid quoting me.

pronouns: prefer neutral ones, others are fine. height: 5'3".

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: Binary Multiplication
« Reply #27 on: February 17, 2010, 09:41:11 am »

Man, why bother with all the applied computational stuff here?  Just do it the abstract way, with arbitrary long bitstrings.

Because its how computers really multiply numbers. I also spent a lot of money on this education and I don't get to use it that often. Because its fun.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Vector

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #28 on: February 17, 2010, 10:59:38 am »

Man, why bother with all the applied computational stuff here?  Just do it the abstract way, with arbitrary long bitstrings.

Because its how computers really multiply numbers. I also spent a lot of money on this education and I don't get to use it that often. Because its fun.

You think it's ... fun ... to impose arbitrary constraints on yourself?

...

Huh.  I must reconsider.
Logged
"The question of the usefulness of poetry arises only in periods of its decline, while in periods of its flowering, no one doubts its total uselessness." - Boris Pasternak

nonbinary/genderfluid/genderqueer renegade mathematician and mafia subforum limpet. please avoid quoting me.

pronouns: prefer neutral ones, others are fine. height: 5'3".

G-Flex

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #29 on: February 17, 2010, 11:10:32 am »

He was bothering with the technical details of it because that's what the conversation had shifted towards, specifically with reference to Armok's claims about multiplication being atomic.
Logged
There are 2 types of people in the world: Those who understand hexadecimal, and those who don't.
Visit the #Bay12Games IRC channel on NewNet
== Human Renovation: My Deus Ex mod/fan patch (v1.30, updated 5/31/2012) ==
Pages: 1 [2] 3