bitwise not - not what I expected

Elaine Jackson elainejackson7355 at home.com
Mon Aug 18 01:26:23 CEST 2003


"Michael Peuser" <mpeuser at web.de> wrote in message
news:bhosrr$u57$06$1 at news.t-online.com...

| I have the impression (may be wrong) that you are working under the
| misconception that there can be a "natural" binary represensation of
| negative numbers!?
| Three conventions have commonly been used so far:
| 1- Complement
| 2-Complement
| Sign tag plus absolut binary values

The last alternative sounds like what I was assuming. If it is, I would argue
that it's pretty darn natural. Here's a little function to illustrate what I
mean:

def matilda(n):     ##  "my tilde"
    if 0<=n<pow(2,29):
        for i in range(1,31):
            iOnes=pow(2,i)-1
            if n<=iOnes:
                return iOnes-n
    else:
         raise






More information about the Python-list mailing list