This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programming Diversions and the fly likes Division without using divide operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Division without using divide operator" Watch "Division without using divide operator" New topic
Author

Division without using divide operator

megha joshi
Ranch Hand

Joined: Feb 20, 2007
Posts: 206
I am looking for the program/algorithm to implement division without
using divide operator?


I know the subtraction solution...I was looking for a more efficient solution ...something like bits manipulation of some kind?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The right shift operator will divide by powers of 2. That's the only shortcut I use. Here are a few notes on Binary Division which might be fun.

Is this a bar bet or a school assignment?
[ October 08, 2007: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1006
    
    3
Implement binary long division. Sure, regular base 10 long division uses a divide operation, but since the binary equivalent needs to arrive at either a 0 or a 1, you could get away with an if statement.

This algorithm would be O(log product), while the subtraction algorithm would be O(result).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Division without using divide operator
 
Similar Threads
the world's smallest number?
Pi day is dead, long live Tau day
EOF Exception while reading Data Section
Multiply to double values
Weird Output !!