SYNOPSIS
result = string.bitrevert(s [, i [, j]])
DESCRIPTION
Completely reverses the order of bits in the string. This flips the order of bytes so the last byte becomes the first byte and so on. In addition, the bit order on each byte is flipped, too.
When i and/or j are given, uses the substring s[i],
s[i+1], ···, s[j].
The default value for i is 1;
the default value for j is the number of characters in s.
RETURN VALUE
A string with all the bits reversed. The result has the same length as the original substring.
NOTES
This is useful for decoding magnetic stripe data that was read backwards.
EXAMPLE
>
>
>
foo = "\x03\x00"
bar = foo:bitrevert()
print (foo:tohex(), bar:tohex())
0300 000F