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,936 questions

51,873 answers

573 users

How to XOR byte arrays in VB.NET

1 Answer

0 votes
Imports System

Class XORBytesDemo
    Private Shared Function XorBytes(ByVal a As Byte(), ByVal b As Byte()) As Byte()
        Dim result As Byte() = New Byte(a.Length - 1) {}

        For i As Integer = 0 To a.Length - 1
            result(i) = CByte((a(i) Xor b(i)))
        Next

        Return result
    End Function

    Private Shared Sub PrintBitsetArray(ByVal label As String, ByVal array As Byte())
        Console.Write(label & ": ")

        For Each b As Byte In array
            Console.Write(Convert.ToString(b, 2).PadLeft(8, "0"c) & " ")
        Next

        Console.WriteLine()
    End Sub

    Public Shared Sub Main()
        Dim a As Byte() = {Convert.ToByte("A"c), Convert.ToByte("e"c), Convert.ToByte("r"c), Convert.ToByte("y"c), Convert.ToByte("n"c)}
        Dim b As Byte() = {Convert.ToByte("A"c), Convert.ToByte("l"c), Convert.ToByte("b"c), Convert.ToByte("u"c), Convert.ToByte("s"c)}
        Dim c As Byte() = XorBytes(a, b)

        PrintBitsetArray("a", a)
        PrintBitsetArray("b", b)
        PrintBitsetArray("c", c)
        Console.Write("c: ")

        For Each ch As Byte In c
            Console.Write(CInt(ch) & " ")
        Next
    End Sub
End Class


' run:
'
' a: 01000001 01100101 01110010 01111001 01101110 
' b: 01000001 01101100 01100010 01110101 01110011 
' c: 00000000 00001001 00010000 00001100 00011101 
' c: 0 9 16 12 29 
'

 



answered Jul 12, 2025 by avibootz

Related questions

1 answer 118 views
118 views asked Jun 5, 2023 by avibootz
1 answer 65 views
65 views asked Jul 12, 2025 by avibootz
1 answer 93 views
1 answer 65 views
65 views asked Jul 12, 2025 by avibootz
1 answer 72 views
72 views asked Jul 12, 2025 by avibootz
1 answer 75 views
75 views asked Jul 12, 2025 by avibootz
1 answer 79 views
...