[Tutor] Binary math?
Bill Mill
bill.mill at gmail.com
Mon Oct 25 21:09:57 CEST 2004
Danny,
I didn't know that int() trick; that's a nice one. Thanks for showing that.
Peace
Bill Mill
bill.mill at gmail.com
On Mon, 25 Oct 2004 11:01:01 -0700 (PDT), Danny Yoo
<dyoo at hkn.eecs.berkeley.edu> wrote:
>
>
> On Mon, 25 Oct 2004, Jeff Peery wrote:
>
> > will python work with binary math?
>
> Hi Jeff,
>
> Just to clarify: most computers work on the principle of binary. There's
> a layer of abstraction that hides the bit-twiddling from us. When we say
> something like 42, the computer is using a bit pattern to represent the
> number 42:
>
> 42 <====> 101010
>
> (2**5 + 2**3 + 2**1)
>
> Python (and most computer systems) will do work using the bit-patterns,
> and a separate program converts those bit-patterns back into a decimal
> representation that's comfortable for humans.
>
>
> > i.e., add subtract binary numbers? is there a specific type that I have
> > to use to define a binary number? thanks.
>
> What are you trying to do? If you're trying to understand how binary math
> works, I'd recommend looking at "Code":
>
> http://www.charlespetzold.com/code/index.html
>
> And if you have a string with the proper bit pattern, then you can use the
> int() builtin:
>
> ###
> >>> int('101010', 2)
> 42
> ###
>
> But I have to admit: I'm still a little confused at what you're asking.
> Please tell us more why you're trying to do binary arithmetic, so we can
> give better help.
>
> Good luck to you!
>
> _______________________________________________
>
>
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list