MCPcopy
hub / github.com/jimmysong/programmingbitcoin / decode_num

Function decode_num

code-ch08/op.py:42–60  ·  view source on GitHub ↗
(element)

Source from the content-addressed store, hash-verified

40
41
42def decode_num(element):
43 if element == b'':
44 return 0
45 # reverse for big endian
46 big_endian = element[::-1]
47 # top bit being 1 means it's negative
48 if big_endian[0] & 0x80:
49 negative = True
50 result = big_endian[0] & 0x7f
51 else:
52 negative = False
53 result = big_endian[0]
54 for c in big_endian[1:]:
55 result <<= 8
56 result += c
57 if negative:
58 return -result
59 else:
60 return result
61
62
63def op_0(stack):

Callers 15

op_checkmultisigFunction · 0.90
op_ifFunction · 0.70
op_notifFunction · 0.70
op_verifyFunction · 0.70
op_ifdupFunction · 0.70
op_pickFunction · 0.70
op_rollFunction · 0.70
op_1addFunction · 0.70
op_1subFunction · 0.70
op_negateFunction · 0.70
op_absFunction · 0.70
op_notFunction · 0.70

Calls

no outgoing calls

Tested by 2

test_op_checksigMethod · 0.56
test_op_checkmultisigMethod · 0.56