 
     // input string should have an even number of characters
     guard (input.characters.count % 2 == 0) else {
-        throw Parameter.Invalid
+        throw Parameter.InvalidHexCharacterCount
     }
 
     // input string should only have hexadecimal characters
     for char in input.lowercaseString.characters {
         guard hex.characters.contains(char) else {
-            throw Parameter.Invalid
+            throw Parameter.InvalidHexCharacter(char: char)
         }
     }
 
     // extract raw bytes from input
     var bytes = [UInt8](count: input.characters.count / 2, repeatedValue: 0)
     var index = input.startIndex
-    for _ in 1...(input.characters.count / 2) {
-        var digit = String(input[index]) + String(input[index.successor()])
+    for i in 1...(input.characters.count / 2) {
+        var str = String(input[index]) + String(input[index.successor()])
+        if let digit = UInt8(str, radix: 16) {
+            bytes[i-1] = digit
+        } else {
+            throw Parameter.InvalidHexString(str: str)
+        }
         index = index.successor().successor()
     }
 
-
+    print (bytes)
     return bytes
 }
 

        return ""
    }

    let bytes = try! convertHexToBytes(input)

    var result = ""


// Exception types
//
enum Parameter: ErrorType {
    case InvalidHexCharacterCount
    case InvalidHexCharacter(char: Character)
    case InvalidHexString(str: String)
}
 
//
