> On 16 Feb 2020, at 17:49, ananthan ananthan 
> <ananthakrishnan15.2...@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
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/PUHAKO5DZ5ZWSY6R3RPKPABDHGGNV7CE/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to