So I have written some swift code that will reverse a hex string but I feel there must be a more elegant way to do it.
Input: "FCDB4B42" Output "424BDBFC"
var string2 = "FCDB4B42"
// reverse the bytes
print (string2)
var string3 = ""
for i in stride(from: 1, to: string2.count, by: 2).reversed() {
string3 = string3 + string2[i - 1] + string2[i]
}
print(string3) // 424BDBFC
extension String {
subscript(idx: Int) -> String {
String(self[index(startIndex, offsetBy: idx)])
}
}
The aim is to reverse it in pairs to preserve the byte values in a more elegant way (usually there is a better way than a ForNext loop).