How to set specific bits in a char with VB.NET

1 Answer

0 votes
Imports System
 
Class Program
    Public Shared Sub Main()
        Dim ch As Byte = 0
        ch = ch Or (1 << 7) ' Set the 7th bit
        ch = ch Or (1 << 3) ' Set the 3rd bit

        Dim binary As String = Convert.ToString(ch, 2).PadLeft(8, "0"c)

        Console.WriteLine(binary)
        Console.WriteLine("Value: " & ch)
    End Sub
End Class
 
 
 
' run:
' 
' 10001000
' Value: 136
'

 



answered Jul 30, 2025 by avibootz
...