How to convert a byte type data to UUID in python

Question:

I am reading the UUID from my board as
b"x93S4E2x8dx9ex8fxe9x11xc1zxd0Ux95'"

How to convert or format this to obtain a 128-bit UUID that reads
[279555d0-7ac1-11e9-8f93-8d3245345393]

Asked By: Quest03

||

Answers:

The Python UUID library will normally cover most of the situations that you need for UUIDs.

https://docs.python.org/3/library/uuid.html

The result I’m get doesn’t match your expected output 100% but I wonder if you have a typo in your question.

This is what I did:

import uuid

raw_id = b"x93S4E2x8dx9ex8fxe9x11xc1zxd0Ux95'"
dev_uuid = uuid.UUID(int=int.from_bytes(raw_id, 'little'))
print(f"Device UUID = {dev_uuid}")

Which gave the output:

Device UUID = 279555d0-7ac1-11e9-8f9e-8d3245345393
Answered By: ukBaz
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.