diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-09 00:40:58 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-09 01:07:37 +0300 |
commit | a985b4593d3f0c788c5e6ef0066bf82ae550cfb8 (patch) | |
tree | e21b447b57350f1261596c2d7cc81fdb30de722f /tests/basics/int-bytes.py | |
parent | 3aa8ee7c9e2e9fd50ffb4b588518bd84b40fef84 (diff) | |
download | micropython-a985b4593d3f0c788c5e6ef0066bf82ae550cfb8.tar.gz micropython-a985b4593d3f0c788c5e6ef0066bf82ae550cfb8.zip |
objint: Implement int.from_bytes() class method and .to_bytes() method.
These two are apprerently the most concise and efficient way to convert
int to/from bytes in Python. The alternatives are struct and array modules,
but methods using them are more verbose in Python code and less efficient
in memory/cycles.
Diffstat (limited to 'tests/basics/int-bytes.py')
-rw-r--r-- | tests/basics/int-bytes.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/basics/int-bytes.py b/tests/basics/int-bytes.py new file mode 100644 index 0000000000..45965ed464 --- /dev/null +++ b/tests/basics/int-bytes.py @@ -0,0 +1,6 @@ +print((10).to_bytes(1, "little")) +print((111111).to_bytes(4, "little")) +print((100).to_bytes(10, "little")) +print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) +print(int.from_bytes(b"\x01\0\0\0\0\0\0\0", "little")) +print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) |