Go range loops over strings return runes (Unicode characters) by default; convert to []byte to iterate over raw bytes.
In Go, a range loop over a string yields Unicode code points (runes), not raw bytes, because strings are UTF-8 encoded sequences of characters. To iterate over the raw bytes instead, you must range over a []byte slice created from the string.
s := "hello"
// Iterates over runes (characters)
for _, r := range s {
// r is a rune (int32)
}
// Iterates over bytes
for _, b := range []byte(s) {
// b is a byte (uint8)
}
Go strings are sequences of characters, not just raw data, so looping over them gives you the actual letters or symbols (runes) regardless of how many bytes they take up in memory. If you need to process the raw underlying data byte-by-byte, you must explicitly convert the string into a byte slice first. Think of it like reading a book: ranging over a string reads the words, while ranging over bytes reads the ink marks on the page.