On 16 Feb 2020, at 17:49, ananthan ananthan <ananthakrishnan15.2001@gmail.com> wrote:

But there is a problem with (0b1101).

5==0b101 -5==-0b101

but we want output -5==1011. so this is not possible by using integers with base designator "0b".

There is no such thing as an 'integers with base designator "0b"'. I think are confusing the type that python uses for an integer with the syntax that python allows you to use to specify an integer in your source code. Python considers the follow the same 5 0o5 0x5 0b101

so we have to use new Python type that represents a "binary number",which accepts number of bits,sign of number.

You can write such a type or just mask off the results of the computation with the python integer type. Your example -5 in 4 bits is this

print( bin( -5 & 0b1111 ) ) 0x1011

Exactly what you want? Barry