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

51,766 answers

573 users

How to XOR byte arrays in Go

2 Answers

0 votes
package main

import (
	"fmt"
)

type T [5]byte

func main() {
	var a, b T
	copy(a[:], "Aeryn")
	copy(b[:], "Albus")

	var c T
	for i := range a {
		c[i] = a[i] ^ b[i]
	}

	fmt.Printf("a: %08b\n", a)
	fmt.Printf("b: %08b\n", b)
	fmt.Printf("c: %08b\n", c)
	fmt.Println("c:", c)
	fmt.Printf("c as string: %q\n", string(c[:]))
}



/*
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]
c as string: "\x00\t\x10\f\x1d"

*/

 



answered Jul 12, 2025 by avibootz
0 votes
package main

import (
	"fmt"
)

func main() {
	a, b := []byte("Aeryn"), []byte("Albus")

	c := make([]byte, len(a))
	for i := range a {
		c[i] = a[i] ^ b[i]
	}

    fmt.Printf("a: %08b\n", a)
    fmt.Printf("b: %08b\n", b)
    fmt.Printf("c: %08b\n", c)
    fmt.Println("c:", c)
    fmt.Printf("c as string: %q\n", string(c[:]))
}



/*
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]
c as string: "\x00\t\x10\f\x1d"

*/

 



answered Jul 12, 2025 by avibootz

Related questions

1 answer 73 views
73 views asked Jul 12, 2025 by avibootz
1 answer 67 views
67 views asked Jul 11, 2025 by avibootz
1 answer 65 views
65 views asked Jul 12, 2025 by avibootz
1 answer 93 views
1 answer 64 views
64 views asked Jul 12, 2025 by avibootz
1 answer 72 views
72 views asked Jul 12, 2025 by avibootz
...