I am using Python. I am trying to determine the correct length of bytes in a binary set of data.
If I assign a variable the binary data...
x = "aabb".decode("hex")
is that the same as
x = b'aabb'
And if so, how do you get how many bytes that is? (It should be 2 bytes)
When I try:
len(x)
I get 4 instead of 2 though...
I am worried that x is turned into a string or something else I don't understand because the data types are so fluid in Python...
x = "aabb".decode("hex"), thenlen(x)returns2. Is that not what it returns on your machine?"aabb".decode("hex") == b'aabb'returns False. Your assumption on these two forms being equal is wrong.b'aabb'is identical to'aabb', but they're different in Python 3. Also,"aabb".decode("hex")in Python 3 raisesAttributeError: 'str' object has no attribute 'decode'. Andb"aabb".decode("hex")in Python 3 raisesLookupError: 'hex' is not a text encoding; use codecs.decode() to handle arbitrary codecs'aabb'to the bytestringb'\xaa\xbb'in a way that works in both versions you can do:import binascii;binascii.unhexlify("aabb")