File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Bit Scan Forward in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic

Bit Scan Forward in java

vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
how can we implement BSF(Bit Scan Forward) assembly code in java in the most efficient way.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
If you've got Jdk 5 or later, check out Integer.numberOfLeadingZeros() and Integer.numberOfTrailingZeros(). Or the same methods in class Long. Otherwise, you have to write a loop to do it with bitshifting and a bitmask. Do you have an application with a real need for this, or is it a homework problem?

"I'm not back." - Bill Harding, Twister
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15084

Vikas' question is about a chess program, see this topic in the Game Development forum: Java Chess Game I made by my self

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Hm, well since the original post has a lot more useful context, I think I'll close this thread and follow up there instead.
I agree. Here's the link:
subject: Bit Scan Forward in java
jQuery in Action, 3rd edition