diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-03-10 00:22:53 +0100 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-03-10 00:22:53 +0100 |
commit | 776883cb80be675fad1fee1ffae5dcdb75f14f64 (patch) | |
tree | e958e122f9cf94cac197f60e04894a76510c2322 /py | |
parent | bc5bffbf65dee144744449a5ec60a3627830caa1 (diff) | |
download | micropython-776883cb80be675fad1fee1ffae5dcdb75f14f64.tar.gz micropython-776883cb80be675fad1fee1ffae5dcdb75f14f64.zip |
py/objint_longlong: Implement mp_obj_int_from_bytes_impl().
This makes int.from_bytes() work for MICROPY_LONGINT_IMPL_LONGLONG.
Diffstat (limited to 'py')
-rw-r--r-- | py/objint_longlong.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/py/objint_longlong.c b/py/objint_longlong.c index b798c91cdf..4ab49f337d 100644 --- a/py/objint_longlong.c +++ b/py/objint_longlong.c @@ -54,7 +54,17 @@ const mp_obj_int_t mp_maxsize_obj = {{&mp_type_int}, MP_SSIZE_MAX}; #endif mp_obj_t mp_obj_int_from_bytes_impl(bool big_endian, size_t len, const byte *buf) { - mp_not_implemented(""); + int delta = 1; + if (!big_endian) { + buf += len - 1; + delta = -1; + } + + mp_longint_impl_t value = 0; + for (; len--; buf += delta) { + value = (value << 8) | *buf; + } + return mp_obj_new_int_from_ll(value); } void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, size_t len, byte *buf) { |