# [Tutor] Binary math?

Jeff Peery jeffpeery at yahoo.com
Mon Oct 25 18:54:07 CEST 2004

```Bill, I am confused, could you explain the first line of code. I can probably then figure out the remaining. all I need to do is find the difference of two binary numbers, converting them to decimal is easy to do. here is the first line of code from the link you sent:

# bstr_pos: only positive integers
# zero     -> ''
# negative -> ''

bstr_pos = lambda n: n>0 and bstr_pos(n>>1)+str(n&1) or ''

thanks.
Jeff

Bill Mill <bill.mill at gmail.com> wrote:
Jeff,

There isn't a built-in type, but it's fairly easy to do. Have a look
at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/219300 for
some ideas on how to do it. If you don't understand those, ask and
I'll try to clarify them for you.

Peace
Bill Mill
bill.mill at gmail.com

On Mon, 25 Oct 2004 09:09:27 -0700 (PDT), Jeff Peery
wrote:
>
>
>
>
> Hello,
>
> will python work with binary math? i.e., add subtract binary numbers? is
> there a specific type that I have to use to define a binary number? thanks.
>
>
>
> Jeff
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20041025/46b9fc19/attachment.htm
```