Home »
VB.Net »
VB.Net Programs
VB.Net program to check the palindrome of the binary number using bitwise operators
Here, we are going to learn how to check the palindrome of the binary number using bitwise operators in VB.Net?
Submitted by Nidhi, on November 26, 2020 [Last updated : February 18, 2023]
Checking the palindrome of the binary number using bitwise operators
Here, we will input an integer number and then find it's binary and check the palindrome of the binary number using a bitwise operator.
Note: A palindrome number is a number, which is equal to its reverse of the same number.
VB.Net code to check the palindrome of the binary number using bitwise operators
The source code to check the palindrome of the binary number using bitwise operators is given below. The given program is compiled and executed successfully.
'VB.Net program to check the palindrome
'of the binary number.
Module Module1
Sub Main()
Dim SIZE As Byte = 8
Dim n As Byte = 0
Dim c(SIZE - 1) As Byte
Dim i As SByte = SIZE - 1
Dim j As SByte = 0
Dim k As SByte = 0
Console.Write("Enter the no ( max range 255): ")
n = Byte.Parse(Console.ReadLine())
Console.WriteLine("Binary representation is: ")
While n > 0
c(i) = (n And 1)
i = i - 1
n = n >> 1
End While
For j = 0 To SIZE - 1 Step 1
Console.Write(c(j))
Next
Console.WriteLine()
j = 0
k = SIZE - 1
While j < k
If Not (c(j) = c(k)) Then
Console.WriteLine("Not palindrome")
Return
End If
j = j + 1
k = k - 1
End While
Console.WriteLine("It's palindrome")
Console.ReadLine()
End Sub
End Module
Output:
Enter the no ( max range 255): 153
Binary representation is:
10011001
It's palindrome
Explanation:
In the above program, we created a module Module1 that contains a function Main(). In the Main() function, we read the integer number and then find it's binary equivalent. After that find, the given number is palindrome or not.
Console.WriteLine("Binary representation is: ")
While n > 0
c(i) = (n And 1)
i = i - 1
n = n >> 1
End While
For j = 0 To SIZE - 1 Step 1
Console.Write(c(j))
Next
Console.WriteLine()
In the above code, we find the binary number of a given integer number.
j = 0
k = SIZE - 1
While j < k
If Not (c(j) = c(k)) Then
Console.WriteLine("Not palindrome")
Return
End If
j = j + 1
k = k - 1
End While
In the above code, we checked the calculated binary number is palindrome or not.
VB.Net Basic Programs »