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 5969 times)

ein

  • Bay Watcher
  • 勝利の女神はここよ~ 早く捕まえてぇ~
    • View Profile
Binary Multiplication
« on: February 10, 2010, 07:27:12 pm »

I was wondering if someone could show me how to multiply with binary.
I've figured out how to do it with the powers of two.
You just take however many zeros there are and put them on the end of the other number.
Two (10) has one zero, and when you multiply it with three (11), you get six (110).
What I want to know is, how do you get 11 and 11 to be 1001? 'N' stuff.

eerr

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #1 on: February 10, 2010, 08:11:32 pm »

How to do it fast, or how to do it.
Logged

ein

  • Bay Watcher
  • 勝利の女神はここよ~ 早く捕まえてぇ~
    • View Profile
Re: Binary Multiplication
« Reply #2 on: February 10, 2010, 08:17:54 pm »

Both.
If I understand how to do it, then I'll be able to learn how to do it faster.
Or something.

Cheddarius

  • Bay Watcher
  • Hrm.
    • View Profile
Re: Binary Multiplication
« Reply #3 on: February 10, 2010, 08:27:01 pm »

Just multiply normally.
Code: [Select]
   11
   11
-----
   11
  110
-----    
  121
-----
  201
-----
 1001
Logged

Ampersand

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #4 on: February 10, 2010, 08:41:33 pm »

Cheddarius, if he doesn't understand how to do Binary multiplication, I'm not sure he'll comprehend that without an explanation of why you have a 2 in there.
Logged
!!&!!

Cheddarius

  • Bay Watcher
  • Hrm.
    • View Profile
Re: Binary Multiplication
« Reply #5 on: February 10, 2010, 08:45:41 pm »

Ah, sorry.
Okay, so you know how you "carry the 10" and such in normal multiplication or addition? This is like that. The 1 and the 1 add up to 2; you "carry the 2" over to the hundreds (or rather, fours) place.
Logged

eerr

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #6 on: February 10, 2010, 09:06:13 pm »

A*B=C
Multiply the first binary digit of A with All the digits of B.
Mulitply the second binary digit of A with All the digits of B.
Multiply the third binary...

(integers have more, chars/ bytes I'm not sure)
... the second last binary digit of A with B.
Multiply the last binary digit of A with B.

Sum All  multiplication. Note that in binary you can end up with a very large remainder which carries over very far.
 1+1=10, 10+10=100, 100+100=1000.



Whether or not this overflows depends on how much space is allocated vs how big the two operands are.
Code: [Select]
   00001000
*  00010000
= 100000000???

Note that my calculation ignores the negative digit, so the exact result would be machine dependant, and contain alot of code I've never studied.



Logged

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Binary Multiplication
« Reply #7 on: February 10, 2010, 10:40:59 pm »

Don't know if this was expressed before, but using the earlier multiplication by a power of two...
(Syntax a<<b means add b zeroes onto the end of a)
Example of one way:
100101*11010

b        a
0 * 100101 << 0+
1 * 100101 << 1+
0 * 100101 << 2+
1 * 100101 << 3+
1 * 100101 << 4=

b        a
1 * 100101 << 1+
1 * 100101 << 3+
1 * 100101 << 4=

b        a
1 * 1001010 << 0 +
1 * 100101000 << 0 +
1 * 1001010000 << 0 =

___1001010+
_100101000+
1001010000=

1111000010

You can reduce it to multiplying a digit, and a << for each digit in one number, then sum the result.
Logged
Eh?
Eh!

ein

  • Bay Watcher
  • 勝利の女神はここよ~ 早く捕まえてぇ~
    • View Profile
Re: Binary Multiplication
« Reply #8 on: February 10, 2010, 11:03:38 pm »

Awesome, thanks.
Also, « is the symbol you're referring to, right?
As in a«b.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Binary Multiplication
« Reply #9 on: February 11, 2010, 09:58:45 am »

No, I think querty means <<, not as a mathematic symbol but as a shift-operator in a number of programming languages.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

eerr

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #10 on: February 11, 2010, 01:02:39 pm »

I would put money that this will be slower than letting the machine handle it.
Logged

sproingie

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

The shift technique is pretty close to how ALUs used to do it in hardware, and it would often take many cycles to execute.  How they do it now is probably way over my head, suffice to say that multiplication is plenty fast these days, especially if you use the FPU.

Logged
Toady is the man who Peter Molyneux wishes he was

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

ein

  • Bay Watcher
  • 勝利の女神はここよ~ 早く捕まえてぇ~
    • View Profile
Re: Binary Multiplication
« Reply #12 on: February 11, 2010, 08:58:36 pm »

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

Vector

  • Bay Watcher
    • View Profile
Re: Binary Multiplication
« Reply #13 on: February 11, 2010, 09:05:45 pm »

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

Not true.  Look up the game of Nim.

Okay, maybe it's useless and you only use it for showing off, but it's an application.


Oh, and all kinds of crap when it comes to taking the power of some number modulo n.  Really useful in algorithms for discrete math and cryptography.
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 #14 on: February 12, 2010, 01:23:21 am »

Just multiply normally.
Code: [Select]
   11
   11
-----
   11
  110
-----    
  121
-----
  201
-----
 1001


... You're seriously using a digit that doesn't even exist in the given number system in order to do arithmetic?

That's kind of like explaining to a third-grader how to multiply numbers and using the digit A in addition to 0-9 in order to do it.

"2" simply doesn't exist as a numeral in binary. 0 does, and 1 does, and "2" in decimal has the same value as "10" in binary, but there's no more a "2" in binary than there is an "A" in decimal or a "Q" in hexadecimal.
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