Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • It's also worth nothing that this will work regardless of the most significant bit and more efficient compared to the other answers. Also could use '>>'. Commented Jul 23, 2012 at 15:20
  • 2
    A direct solution like this is certainly faster than calling any library method. Sometimes you just have to fiddle with the the bits directly with a few lines of code rather than incurring all the extra overhead of library method calls. Commented Feb 9, 2016 at 16:28
  • And this converts between languages well so is good for multi language software development. Commented Nov 22, 2019 at 22:35