- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Golang Program to check if the binary representation of a number is palindrome or not
Examples
For example, 101, 11, 11011, 1001001 are Palindrome. 100, 10010 are not Palindrome.
Approach to solve this problem
Step 1 − Convert number into binary representation.
Step 2 − Traverse the converted binary representation from both side and check whether representation is palindrome or not.
Example
package main import ( "fmt" "strconv" ) func IsPalindrome(n int) bool{ rev := 0 k := n for k != 0 { rev = (rev << 1) | (k & 1) k = k >> 1 } return n == rev } func main(){ n := 3 fmt.Printf("Binary representation of %d is: %s.\n", n, strconv.FormatInt(int64(n), 2)) if IsPalindrome(n) == true{ fmt.Println("Palindrome") } else { fmt.Println("Not a Palindrome") } }
Output
Binary representation of 3 is: 11. Palindrome
- Related Articles
- Java program to check if binary representation is palindrome
- C# program to check if binary representation is palindrome
- Python program to check if binary representation is palindrome?
- Check if binary representation of a number is palindrome in Python
- Write a C# program to check if a number is Palindrome or not
- Write a Golang program to check whether a given number is a palindrome or not
- Recursive program to check if number is palindrome or not in C++
- C++ Program to Check Whether a Number is Palindrome or Not
- C# program to check if a string is palindrome or not
- Python program to check if a string is palindrome or not
- C Program to check if an Array is Palindrome or not
- Swift Program to check if an Array is Palindrome or not
- Golang Program to check a given number is finite or not
- Check if number is palindrome or not in Octal in Python
- Check if the Decimal representation of the given Binary String is divisible by K or not

Advertisements