package main
import (
"encoding/hex"
"fmt"
)
func main() {
// Step 1: Define a byte slice with the data you want to encode
data := []byte("Hello, World!")
// Step 2: Use the hex.EncodeToString function to encode the data to a hexadecimal string
encodedString := hex.EncodeToString(data)
// Step 3: Print the original data and the encoded string
fmt.Printf("Original Data: %s\n", data)
fmt.Printf("Encoded String: %s\n", encodedString)
// Step 4: Use hex.DecodeString to decode the encoded string back to the original data
decodedData, err := hex.DecodeString(encodedString)
if err != nil {
fmt.Println("Error decoding hex string:", err)
return
}
// Step 5: Print the decoded data
fmt.Printf("Decoded Data: %s\n", decodedData)
}