This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/CC3200_NFC_CARD_READER: how to traverse a string to use the data and assign another to another string

Part Number: CC3200

Tool/software: Code Composer Studio

hello, I explain to you with extension my problem, I have a string in hexadecimal and I want to pass it to ascii, I can not think of another idea to go through it and do an if with each of the data assigning the value that equals, but for this I need to know how go through that string and then how to assign value 1 of the string to the corresponding value. If you know any way to transform the chain to ascii without so much code, please do me a favor, thanks. I'm trying in the example of SDK nfc-reader to pass the string that returns me in hexadecimal pass it to ascii, in case you can help me exactly with the case I'm playing, thanks.

Regards

  • What do you mean by "pass it to Ascii"?
    Do you want a decimal equivalent or change each hex digit to its ascii equivalent?
    If the last, just create a 16 element array with the ascii digits in order. Simply use the value of the hex digit as the index to the array.

    For the first use, for example, strtoul().

    but really, this is a C problem.
  • In effect I want to pass the numbers in hexadecimal to their equivalent in ASCII. It can be a problem of C but I did not know where to ask I'm sorry, the problem is that I do not know how to go through the data chain and assign another chain the equivalent, could you help me with this problem, otherwise, I could refer to you in a message Private and could you help me?
  • You really did not give me enough details, but:
    
    #define SIZE 16
    uint8_t hexdata[SIZE];
    char ascii_str[2*SIZE+1];
    
    char table[16] = {'0', '1', '2', '3', /* ...*/ 'e', 'f'};
    
    int char_idx=0;
    int i;
    uint8_t nibble;
    
    for (i=0; i<SIZE; i++)
    {
        nibble = ((hexdata[i] >> 4) & 0x0F); // top 4 bits
        ascii_str[char_idx++] = table[nibble];
    
        nibble = (hexdata[i] & 0x0f) // bottom 4 bits
        ascii_str[char_idx++] = table[nibble];
    }
    
    ascii_str[char_idx] = '\0'