468,496 Members | 1,790 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,496 developers. It's quick & easy.

how to divide or multiply two numbers with using bitwise operator

please can anyone tell me how to multiply or divide,or add or subtracted two
numbers
Oct 8 '06 #1
3 23636
D_C
293 100+
To multiply and divide by powers of two, use the bitwise shift operator.

dividend / 2^n = (dividend >> n)
factor * 2^n = (factor << n).

bitwise addition and subtraction is done using xor.
Expand|Select|Wrap|Line Numbers
  1.  1101
  2. 0110
  3. =====
  4.  1011
  5. +c(b)
  6. =====
  7.  xxxx
Where c(b) is the carry in terms of bits. The carry bits depend on whether it's addition or subtraction that's being performed, and maybe whether the numbers are signed or unsigned.
Oct 8 '06 #2
that was nice of u.

But how to multply 4*3=12
Oct 9 '06 #3
D_C
293 100+
3 << 2, since 2^2 = 4.

If you mean 3*5, that's more trouble. You would have to do
Expand|Select|Wrap|Line Numbers
  1. 011   // 100
  2.  000  //  00
  3.   011 //   1
  4. ===== // ===
  5. 01111 // 101
Why don't you look at how multipliers are implemented in hardware. The idea is to put it into binary, and if the bit is a 1, shift it appropriately, and add it. Do that for all bits. Just like we learned in grade school, but with base two instead of base ten.
Oct 9 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Nobody | last post: by
14 posts views Thread by Tony Johansson | last post: by
12 posts views Thread by sandy_pt_in | last post: by
5 posts views Thread by per.nordlow | last post: by
11 posts views Thread by vips | last post: by
8 posts views Thread by gavinstone007 | last post: by
1 post views Thread by Justin.Velazquez | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.