This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
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 OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP 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: 3019
    
  10
I think that's the fastest way, right there.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8626
    
  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: 40436
    
  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