"Vicent" <vgi...@gmail.com> wrote

Anyway, I am working with Python 2.5.4, and I am interested in defining a new type called "bit" (if possible), which represents a number that can only take values 0 or 1 —that's what we would call a "binary variable", in a
Mathematical Programming context.

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.

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to