gpt4 book ai didi

c++ - 如何将字符串(字符数组)中的 UUID 转换为静态 uint8_t adv_data[31]

转载 作者:太空狗 更新时间:2023-10-29 20:36:36 24 4
gpt4 key购买 nike

我有一个像这样的 iBeacon UUID "3bdb098f-b8b0-4d1b-baa2-0d93eb7169c4" 我需要它看起来很像:

static uint8_t adv_data[31] = { 0x02,0x01,0x06, 0x1A,0xFF,0x4C,0x00,0x02,0x15,0x71,0x3d,0x00,0x00,0x50,0x3e,0x4c,0x75,0xba,0x94,0x31,0x48,0xf1,0x8d,0x94,0x1e,0x00,0x00,0x00,0x00,0xC5 };

我需要一种在代码中转换它的方法,但是“手动”转换它的一次性方法也很酷(加上 arduino 代码不必每次都处理转换)

最佳答案

一次红色两个字符,将它们转换成十六进制值对应的数字。循环执行。遇到 '-' 字符时跳过。将数组中的“当前”元素设置为该值。将“当前”设置为数组中的下一个元素。

像这样的代码

while (not at end of string)
{
char1 = get next character from string;
char2 = get next character from string;
value = make int from hex characters(char1, char2);
array[current++] = value;
}

关于c++ - 如何将字符串(字符数组)中的 UUID 转换为静态 uint8_t adv_data[31],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37698164/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com