my dog learned polymorphism*
The moose likes Java in General and the fly likes fastest way to access certain digit in long Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "fastest way to access certain digit in long" Watch "fastest way to access certain digit in long" New topic
Author

fastest way to access certain digit in long

Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
lets say I have :


and I want to get the fourth digit from behind (in this case, the number would be 7). What's the fastest way to get this number? Is there any faster way than this?

Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3003
    
    9
I think that's the fastest way, right there.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7552
    
  18

Hendra Kurniawan wrote:Is there any faster way than this?

Not unless you want to get really geeky

And I'd advise strongly against it.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
It is much quicker if you want to access the i-th bit, or a digit in hexadecimal, which you can do with the << & and >> operators.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: fastest way to access certain digit in long
 
Similar Threads
multiples project (three five) project euler
Sum Of Digits
Packed decimal conversion - Java
substring to just get the last character
Quickest way to read in a Web page