Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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.
–
–
–
–
–
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
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.