cancel
Showing results for 
Search instead for 
Did you mean: 

Append uint32 to string for BLE local name

kcire L.
Associate III

I think this is more of a c programming question rather than a MCU question, but I figured I would ask anyway. I am trying to append the chip ID from an STM32WB onto the BLE local name for my application and am having trouble figuring out how to do this.

my local name is a const char *name = TEST

My chip id is a uint32_t Device_ID which was read from the device register (0x1FFF7580).

lets say the Device_ID = 0x8BE4...

How can I combine these two such that my local name ends up being "TEST 8BE4"

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

This should do it:

sprintf(name, "TEST %04X", id);

The length of the resulting string can be calculated with strlen(name).

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
MM..1
Chief II
   char name[32]; //or how is max name len
 
   sprintf(name, "TEST %x", id);
or
   sprintf(name, "TEST %08x", id);
 

TDK
Guru

This should do it:

sprintf(name, "TEST %04X", id);

The length of the resulting string can be calculated with strlen(name).

If you feel a post has answered your question, please click "Accept as Solution".