Given a positive integer **n**. The problem is to check if the number is Fibbinary Number or not. Fibbinary numbers are integers whose binary representation contains no consecutive ones.

**Examples :**

Input : 10 Output : Yes Explanation: 1010 is the binary representation of 10 which does not contains any consecutive 1's. Input : 11 Output : No Explanation: 1011 is the binary representation of 11, which contains consecutive 1's.

**Approach:** If (n & (n >> 1)) == 0, then ‘n’ is a fibbinary number Else not.

## C++

`// C++ implementation to check whether a number ` `// is fibbinary or not ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// function to check whether a number ` `// is fibbinary or not ` `bool` `isFibbinaryNum(unsigned ` `int` `n) { ` ` ` ` ` `// if the number does not contain adjacent ones ` ` ` `// then (n & (n >> 1)) operation results to 0 ` ` ` `if` `((n & (n >> 1)) == 0) ` ` ` `return` `true` `; ` ` ` ` ` `// not a fibbinary number ` ` ` `return` `false` `; ` `} ` ` ` `// Driver program to test above ` `int` `main() { ` ` ` `unsigned ` `int` `n = 10; ` ` ` `if` `(isFibbinaryNum(n)) ` ` ` `cout << ` `"Yes"` `; ` ` ` `else` ` ` `cout << ` `"No"` `; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation to check whether ` `// a number is fibbinary or not ` `class` `GFG { ` ` ` ` ` `// function to check whether a number ` ` ` `// is fibbinary or not ` ` ` `static` `boolean` `isFibbinaryNum(` `int` `n) { ` ` ` ` ` `// if the number does not contain ` ` ` `// adjacent ones then (n & (n >> 1)) ` ` ` `// operation results to 0 ` ` ` `if` `((n & (n >> ` `1` `)) == ` `0` `) ` ` ` `return` `true` `; ` ` ` ` ` `// not a fibbinary number ` ` ` `return` `false` `; ` ` ` `} ` ` ` ` ` `// Driver program to test above ` ` ` `public` `static` `void` `main(String[] args) { ` ` ` ` ` `int` `n = ` `10` `; ` ` ` ` ` `if` `(isFibbinaryNum(n) == ` `true` `) ` ` ` `System.out.println(` `"Yes"` `); ` ` ` `else` ` ` `System.out.println(` `"No"` `); ` ` ` `} ` `} ` ` ` `// This code is contributed by ` `// Smitha Dinesh Semwal ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to check if a number ` `# is fibinnary number or not ` ` ` `# function to check whether a number ` `# is fibbinary or not ` `def` `isFibbinaryNum( n): ` ` ` ` ` `# if the number does not contain adjacent ` ` ` `# ones then (n & (n >> 1)) operation ` ` ` `# results to 0 ` ` ` `if` `((n & (n >> ` `1` `)) ` `=` `=` `0` `): ` ` ` `return` `1` ` ` ` ` `# Not a fibbinary number ` ` ` `return` `0` ` ` `# Driver code ` `n ` `=` `10` ` ` `if` `(isFibbinaryNum(n)): ` ` ` `print` `(` `"Yes"` `) ` `else` `: ` ` ` `print` `(` `"No"` `) ` ` ` `# This code is contributed by sunnysingh ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation to check whether ` `// a number is fibbinary or not ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// function to check whether a number ` ` ` `// is fibbinary or not ` ` ` `static` `bool` `isFibbinaryNum(` `int` `n) { ` ` ` ` ` `// if the number does not contain ` ` ` `// adjacent ones then (n & (n >> 1)) ` ` ` `// operation results to 0 ` ` ` `if` `((n & (n >> 1)) == 0) ` ` ` `return` `true` `; ` ` ` ` ` `// not a fibbinary number ` ` ` `return` `false` `; ` ` ` `} ` ` ` ` ` `// Driver program to test above ` ` ` `public` `static` `void` `Main() { ` ` ` ` ` `int` `n = 10; ` ` ` ` ` `if` `(isFibbinaryNum(n) == ` `true` `) ` ` ` `Console.WriteLine(` `"Yes"` `); ` ` ` `else` ` ` `Console.WriteLine(` `"No"` `); ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation to check whether ` `// a number is fibbinary or not ` ` ` `// function to check whether a number ` `// is fibbinary or not ` `function` `isFibbinaryNum(` `$n` `) ` `{ ` ` ` ` ` `// if the number does not contain ` ` ` `// adjacent ones then (n & (n >> 1)) ` ` ` `// operation results to 0 ` ` ` `if` `((` `$n` `& (` `$n` `>> 1)) == 0) ` ` ` `return` `true; ` ` ` ` ` `// not a fibbinary number ` ` ` `return` `false; ` `} ` ` ` `// Driver code ` `$n` `= 10; ` `if` `(isFibbinaryNum(` `$n` `)) ` ` ` `echo` `"Yes"` `; ` `else` ` ` `echo` `"No"` `; ` ` ` `// This code is contributed by mits ` `?> ` |

*chevron_right*

*filter_none*

**Output :**

Yes

Time Complexity: O(1).

## Recommended Posts:

- How to swap two numbers without using a temporary variable?
- Count total set bits in all numbers from 1 to n
- Add two numbers without using arithmetic operators
- Binary representation of a given number
- Russian Peasant (Multiply two numbers using bitwise operators)
- Check if binary representation of a number is palindrome
- Subtract two numbers without using arithmetic operators
- 1's and 2's complement of a Binary Number
- Gray to Binary and Binary to Gray conversion
- Count strings with consecutive 1's
- Print first n numbers with exactly two set bits
- Find Two Missing Numbers | Set 2 (XOR based solution)
- Check if a number can be expressed as a sum of consecutive numbers
- Length of the Longest Consecutive 1s in Binary Representation
- Check if bits of a number has count of consecutive set bits in increasing order

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.