This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nordic implementation of itoa?

I want to convert an integer to a char array and feel like this is something an nRF library may have already implemented. Nothing showed up after an initial search of itoa in the documentation although it is likely to have another name.

Does this already exist? Should I just make my own limited version? I'd prefer to use an existing, well-tested one so I have one less piece of code to maintain. Thank you.

  • I recently had to look into a simple way of converting the device's built in serial number to a decimal ascii character array. You may find sprintf() in stdio.h to work well enough for your purposes, just provide it a large enough buffer and make sure to use the correct format parameter for your application. For example, below is what I used to convert the unsigned 64 bit hex nordic serial number to a decimal string:

    #include <stdio.h>
    #include <stdint.h>
    #include <nrf.h>
    #include "nrf_soc.h"
    ...
    int serial_number_string_length;
    uint64_t const * const serial_number = (uint64_t const *) &NRF_FICR->DEVICEID[0];
    static char serial_number_string[21]; // Max decimal character length is 20 digits (result of 2^64)
    serial_number_string_length = sprintf(serial_number_string, "%llu", *serial_number);
    
  • Yes, Kiel v5.12. This still isn't working for me though and I don't seem to have an ability to really swap out compilers. Thank you for your help anyways.

Related