Linked Questions

19 votes
2 answers
15k views

I have a bitboard and I want to check in C if there is ONLY one bit set to 1. #include <stdint.h> typedef uint64_t bboard; bboard b = 0x0000000000000010; if (only_one_bit_set_to_one (b)) // in ...
Pioz's user avatar
  • 6,331
7 votes
4 answers
18k views

Possible Duplicate: How to check if a number is a power of 2 I made the following code, but it's not working. The compiler gives an error that for a missing ) and expression syntax error. What is ...
user avatar
5 votes
9 answers
40k views

Possible Duplicate: How to check if a number is a power of 2 I want to determine if a number is in 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 ... I tried this: public static void ...
Shimmy Weitzhandler's user avatar
0 votes
2 answers
4k views

Possible Duplicate: How to check if a number is a power of 2 This question has been asked in an interview. How to check if a number is in 2^n format {1, 2, 4, 8, 16, 32, ....} without using *, ...
Ashwini Agarwal's user avatar
1 vote
2 answers
10k views

Possible Duplicate: How to check if a number is a power of 2 How could I write a method that would return true if passed in the value 2, 4, 8, 32, 64, and so on?
Tyler Petrochko's user avatar
5 votes
2 answers
730 views

Possible Duplicates: Query about working out whether number is a power of 2 How to check if a number is a power of 2 I require a function body for this prototype: bool isPOT(int x); So it ...
P i's user avatar
  • 31.3k
2 votes
1 answer
637 views

Possible Duplicate: How to check if a number is a power of 2 fastest way to find a given number 'n' can be expressed as 2^m ex: 16= 2^4 naive solution: divide given number by 2 until the ...
realnumber's user avatar
  • 2,314
-1 votes
3 answers
230 views

I know this method and it is not efficient enough (a/2)%2==0;
g.i joe's user avatar
  • 11
0 votes
1 answer
2k views

Note, this is not a dupe of this question: Testing if a bitmask has one and only one flag I need to validate whether or not a bitmask consists of multiple flags. I've come up with this method, but ...
oscilatingcretin's user avatar
3 votes
1 answer
1k views

What is the most efficient (in terms of speed and space) way to check if a decimal number only has a single '1' in its binary representation without using special functions (math, numpy, etc.)? e.g. ...
mayankmehtani's user avatar
-3 votes
3 answers
977 views

public class test{ public static void main(String[] args) { int a=536870912; System.out.print((Math.log(a)/Math.log(2))); } } 536870912 is a number that is power of two, but the result is ...
Wang Liang's user avatar
0 votes
1 answer
507 views

Sorry if this is a stupid question but I just want to know whats the actual meaning of the if statement below. int rank, numprocs; MPI_Status status; MPI_Init(&argc,&argv); MPI_Comm_size( ...
Henry Lau's user avatar
-3 votes
2 answers
125 views

I want to test whether any single bit is set in a C int. I don't care which bit it is. Equivalent to if (1 == count_bits (n)) I'm curious if there is a non-looping algorithm for this which does not ...
spraff's user avatar
  • 33.7k
-3 votes
2 answers
78 views

What is the fastest (in asymptotic worst-case time complexity) algorithm for determining if a sum of arbitrary positive integers is a power of two?
Elliot Gorokhovsky's user avatar
0 votes
1 answer
93 views

This question is from job interview...Use this template to write a C++ function that checks if a positive integer is a power of two. bool p(int n) { return ********; } You have to replace the 8 '*...
delta-terminator's user avatar

15 30 50 per page