Reputation: 357
I'm following a tutorial and it says the UUID is 65210001-28D5-4B7B-BADF-7DEE1E8D1B6D
then he adds it to the code in this format, without explaining how the conversion happened:
// Simple Service UUID: 65210001-28D5-4B7B-BADF-7DEE1E8D1B6D
static struct bt_uuid_128 simple_service_uuid =
BT_UUID_INIT_128(0x6d, 0x1b, 0x8d, 0x1e, 0xee, 0x7d, 0xdf, 0xba, 0x7b,
0x4b, 0xd5, 0x28, 0x01, 0x00, 0x21, 0x65);
I'm curious, what format is 0x6d, 0x1b, 0x8d, 0x1e, 0xee, 0x7d, 0xdf, 0xba, 0x7b,0x4b, 0xd5, 0x28, 0x01, 0x00, 0x21, 0x65
exactly? Hex?
How can I get from the UUID to the array? I've tried hex conversions and some other python encoding, but I can't create anything close. I'm looking to do the conversion in python.
Upvotes: 1
Views: 1304
Reputation: 357
Here is the python solution thanks to Patrick Artners help:
uuid = input('Enter a UUID: ')
uuid = uuid.replace('-', '')
uuid = uuid[::-1] #reverse the string
hexArrayStr = ''
splitToTwos = map(''.join, zip(*[iter(uuid)]*2))
count = 0
for v in splitToTwos:
count+=1
hexArrayStr = hexArrayStr + ('0x'+(v[::-1]).lower())
if count != 16:
hexArrayStr = hexArrayStr + ', '
print(hexArrayStr)
prints 0x6d, 0x1b, 0x8d, 0x1e, 0xee, 0x7d, 0xdf, 0xba, 0x7b, 0x4b, 0xd5, 0x28, 0x01, 0x00, 0x21, 0x65
Upvotes: 2