Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,894 questions

51,825 answers

573 users

How to check if the binary representation of a number is a palindrome in VB.NET

3 Answers

0 votes
Imports System

Public Class Program
	Public Shared Function Reverse(ByVal str As String) As String
        Dim arr() As Char = str.ToCharArray()

        Array.Reverse(arr)

		Return New String(arr)
    End Function

    Public Shared Function isPalindrome(ByVal n As Integer) As Boolean
		Return Convert.ToString(n, 2) = Reverse(Convert.ToString(n, 2))
    End Function

	Public Shared Sub Main()
        Dim n As Integer = 27
		
        Console.WriteLine(Convert.ToString(n, 2))
		
        Console.WriteLine((If(isPalindrome(n), "Yes", "No")))
    End Sub
End Class
	
	

' run:
'
' 11011
' Yes
'

 



answered Jul 14, 2022 by avibootz
0 votes
Imports System
Imports System.Linq

Public Class Program
    Public Shared Function isPalindrome(ByVal n As Integer) As Boolean
        Return Convert.ToString(n, 2) = String.Join("", Convert.ToString(n, 2).Reverse())
    End Function
 
    Public Shared Sub Main()
        Dim n As Integer = 27
         
        Console.WriteLine(Convert.ToString(n, 2))
         
        Console.WriteLine((If(isPalindrome(n), "Yes", "No")))
    End Sub
End Class
     
     
 
' run:
'
' 11011
' Yes
'

 



answered Jul 14, 2022 by avibootz
0 votes
Imports System
Imports System.Linq
 
Public Class Program
    Public Shared Function is_binary_representation_of_number_palindrome(ByVal num As Integer) As Boolean
        Dim binary As String = Convert.ToString(num, 2)
         
        Console.WriteLine(binary)
         
        Return binary.Equals(String.Join("", binary.Reverse()))
    End Function
 
    Public Shared Sub Main(ByVal args As String())
        Dim num As Integer = 153
 
        If is_binary_representation_of_number_palindrome(num) Then
            Console.Write("Palindrome")
        Else
            Console.Write("Not Palindrome")
        End If
    End Sub
End Class
 
 
' run:
'
' 10011001
' Palindrome
'

 



answered Jan 8, 2024 by avibootz
...