aspose file tools*
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
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: 3018
    
  10
I think that's the fastest way, right there.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8250
    
  23

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: 39885
    
  28
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.
 
 
subject: fastest way to access certain digit in long