core: few fixes in utils

This commit is contained in:
mich 2019-02-01 17:12:27 +01:00
parent 96eb9c4148
commit 85275267df
3 changed files with 6 additions and 6 deletions

View File

@ -292,7 +292,7 @@ def bitstr_to_int(bitstr):
Returns:
val (signed integer)
"""
uint = int(bitstr, 2)
uint, bitlen = int(bitstr, 2), len(bitstr)
if uint >= 1<<(bitlen-1):
# 2's complement
return uint - (1<<bitlen)
@ -324,7 +324,7 @@ def bitlist_to_int(bitlist):
Returns:
val (signed integer)
"""
uint = bitlist_to_uint(bitlist)
uint, bitlen = bitlist_to_uint(bitlist), len(bitlist)
if uint >= 1<<(bitlen-1):
# 2's complement
return uint - (1<<bitlen)

View File

@ -1635,7 +1635,7 @@ def pack_val(*val):
else:
# a.b) unaligned access
assert( 0 <= junc < 256 )
head, buf, trail = bytes_lshift_bnd(pack_buf, pack_len_le, 8-rest_bit)
head, buf, trail = bytes_lshift_bnd(pack_buf, pack_len, 8-rest_bit)
# complete the junction byte and append it
# with the shifted buffer
len_bit += pack_len
@ -2034,7 +2034,7 @@ def pack_val(*val):
u = v[1]+(1<<v[2])
if u < (1<<(v[2]-1)):
u = 1<<(v[2]-1)
v_bytes = int_le_to_bytes(v[1], v[2])
v_bytes = uint_le_to_bytes(u, v[2])
# a) append pack_val first, if exist
if pack_fmt is not None:
pack_buf = pack(''.join(pack_fmt), *pack_val)

View File

@ -1596,7 +1596,7 @@ def pack_val(*val):
else:
# a.b) unaligned access
assert( 0 <= junc < 256 )
head, buf, trail = bytes_lshift_bnd(pack_buf, pack_len_le, 8-rest_bit)
head, buf, trail = bytes_lshift_bnd(pack_buf, pack_len, 8-rest_bit)
# complete the junction byte and append it
# with the shifted buffer
len_bit += pack_len
@ -1996,7 +1996,7 @@ def pack_val(*val):
u = v[1]+(1<<v[2])
if u < (1<<(v[2]-1)):
u = 1<<(v[2]-1)
v_bytes = int_le_to_bytes(v[1], v[2])
v_bytes = uint_le_to_bytes(u, v[2])
# a) append pack_val first, if exist
if pack_fmt is not None:
pack_buf = pack(''.join(pack_fmt), *pack_val)