[Tutor] Defining "bit" type

Vicent vginer at gmail.com
Sat Jan 24 18:37:52 CET 2009


On Sat, Jan 24, 2009 at 18:19, Alan Gauld <alan.gauld at btinternet.com> wrote:

>
> If its a single binary digit you want then it would be relatively easy to
> define a class. The operations you need would largely be the
> comparison and arithmetic ones. But while its not difficult it is
> tedious and you would need to think about the Exceptions you
> need to raise for carry errors etc. For example what would be the
> result of adding two Bits both valued 1. Would the result be a
> new zero Bit or an Overflow exception?
>
> Alan G.
>

That's a good question...

Now, when you add up two booleans valued "True", you get 2:

>>> a = True
>>> b = True
>>> a+b
2

So, maybe I can just build a class that is like a "translator" of True/False
into 1/0, but that also admits 1/0 in assignation statements.

For my purposes, maybe it is not necessary to handle with many unexpected
behaviors...

As I am a beginner, I still don't know how to build that class, but I guess
Wayne gave me the clue, or something to play with.



-- 
Vicent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090124/ba054e71/attachment.htm>


More information about the Tutor mailing list