# Golang Program to check if the binary representation of a number is palindrome or not

Go ProgrammingServer Side ProgrammingProgramming

## 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

Live Demo

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
{"ft_lang_label":"__label__en","ft_lang_prob":0.6619234,"math_prob":0.8360269,"size":2170,"snap":"2022-05-2022-21","text_gpt3_token_len":548,"char_repetition_ratio":0.21421976,"word_repetition_ratio":0.20654912,"special_character_ratio":0.26820275,"punctuation_ratio":0.06970509,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97196025,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-25T12:32:25Z\",\"WARC-Record-ID\":\"<urn:uuid:12b18055-eb63-4760-8f47-a6fd104f6249>\",\"Content-Length\":\"30995\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:71adc48d-b7eb-4559-983f-5845d85bb4f3>\",\"WARC-Concurrent-To\":\"<urn:uuid:c9707c9f-7ff6-4e6a-b36d-64f2aee91dea>\",\"WARC-IP-Address\":\"192.229.210.176\",\"WARC-Target-URI\":\"https://www.tutorialspoint.com/golang-program-to-check-if-the-binary-representation-of-a-number-is-palindrome-or-not\",\"WARC-Payload-Digest\":\"sha1:SEPWGQIT6DA6QGI5A7MHZFK6IVF4X6FS\",\"WARC-Block-Digest\":\"sha1:5H33UEDG2C2P5PPZSZYESNDNJMO7YTNG\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662587158.57_warc_CC-MAIN-20220525120449-20220525150449-00715.warc.gz\"}"}