#n = input signed number (2's complement)
#b = number of bits used for representing input singed number
#k = number of bit by which number n is to be sign extended
def signExtend(n,b,k):
# Function should return signed number of bit length (b+k) with k most significant bits as sign bits
For example, if b=4, k=3, n = 10 (2's complement representation 4'b1010), then the function should return 122 (2's complement representation 7'b1111010). However if n = 5 (4'b0101), then the function should return 5 (7'b0000101).
I have seen some posts (such as Two's complement sign extension python? ) which seem to do sign extension, but the result they produce is very different than what I expect to produce above. How to achieve above in Python ?