0

The following snippet I used to convert Hex string to NSData. Here i ams ending text field input as 1234, the output supposed to be <1234> , instead am getting

some : 20 bytes - count : 20 ▿ pointer : 0x0000000283acc580 - pointerValue : 10799072640 ▿ bytes : 20 elements - 0 : 53 - 1 : 54 - 2 : 0 - 3 : 0 - 4 : 0 - 5 : 0 - 6 : 0 - 7 : 0 - 8 : 0 - 9 : 0 - 10 : 0 - 11 : 0 - 12 : 0 - 13 : 0 - 14 : 0 - 15 : 0 - 16 : 0 - 17 : 0 - 18 : 0

  - 19 : 0



var command = inputTextField.text
        command = command?.replacingOccurrences(of: " ", with: "")

        let commandToSend = NSMutableData()
        var wholeByte = CUnsignedChar()

        var byte_char: [CChar] = [0, 0, 0]

        for i in 0..<command!.count/2{

            byte_char[0] = CChar((command! as NSString).character(at: i*2))
            byte_char[1] = CChar((command! as NSString).character(at: (i*2)+1))
            wholeByte = CUnsignedChar(strtoul(byte_char, nil, 16))
            commandToSend.append(&wholeByte, length: 1)

        }

Expected result : <1234> with the same kind of snippet objetive c valid

Sai Dammu
  • 11
  • 2

0 Answers0