Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6934243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:56:06+00:00 2026-05-27T11:56:06+00:00

I once encountered a method of determining if a number x is a power

  • 0

I once encountered a method of determining if a number x is a power of 2 by doing the following:

X&(x-1) followed by a 0 test, if the result is 0 then it means there is only one 1 bit in the number and that it is a power of 2. But the problem is it can’t be used for signed int? I am just wondering if the only exception for a signed int is that it may be the signed bit that is the only one bit, if this is the case I could simply add another test and be done with it. Or does it have other exceptions that this method may not apply to a signed int. since I really wanna use it in java, I hope I can adopt it in some enhanced way. Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:56:06+00:00Added an answer on May 27, 2026 at 11:56 am

    It doesn’t matter; just test for negatives. A power of a positive number is never negative, so you can safely say that any negative number given isn’t a power of two.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I once encountered an operator ===. But I don remember what it was.. or
Once again I was in a design review, and encountered the claim that the
I encountered an issue using jQuery's .delegate() method on IE8 when removing the elements
More than once I've encountered the situation where a UIView (subclass) ends up on
I recently encountered a bug in java where JList will fire the valueChanged() method
We've encountered an access violation on our test machine, in Entity Framework code. I'm
The docs here say: Then, once spork is running, invoke testdrb (e.g. testdrb -Itest
Once again, I'm at a loss with IE7 on this one. I'm making a
Once upon a time I was thought by more advanced web developers (gee, when
Once you've got the hang on your typical R error messages they're quite useful.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.