'MAC address conversion into byte array in python
I have a mac address in this format
00:45:36:45:f2:00
I want to convert this mac address into byte array. I mean, by removing the ':' in between, I get total of 6 bytes and those 6 bytes should sit as six bytes in a byte array. And how is that byte array converted into an integer? Is there any in-built function in python that would do that with very very less execution time(like in microseconds)?
Solution 1:[1]
In python version 3.10.1
code is
import binascii
macbytes = binascii.unhexlify(addr.replace(':', ''))
the replace function/definition should be provided with strings-' ' and not bytes-b' '
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mahadev |
