RE: unsigned int \ long

Discussion in 'Python' started by Roman Yakovenko, Aug 13, 2003.

  1. 1. Bitwise operations
    ~210 | 118 == -129

    I'd like to get 127 ( of course if I work within byte or smth like this ).

    Today in order to get it I have to write ( ~210 | 118 ) & 0xFF

    2. Example
    def print_selection( some_list, range=(0,-1) ):
    lower = max( 0, range[0] )
    upper = min( len( some_list ), unsigned_int( range[1] ) )
    print some_list[lower:upper]

    instead I have to write

    def print_selection( some_list, range=(0,-1) ):
    lower = max( 0, range[0] )
    upper = range[1]
    if upper < 0 or upper > len( some_list )
    upper = len( some_list )
    print some_list[lower:upper]

    Thanks for help.

    Roman.

    > -----Original Message-----
    > From: Andres Viikmaa [mailto:]
    > Sent: Wednesday, August 13, 2003 9:49 AM
    > To:
    > Subject: Re: unsigned int \ long
    >
    >
    > look module struct -- Interpret strings as packed binary data
    >
    > Andres
    >
    > "Roman Yakovenko" <> wrote in message
    > news:...
    > Hi. I need to work with integer as unsigned integer, but
    > I can't find documentation how can I do it.
    >
    > Some reference on this will be appreciated.
    >
    > For example (unsigned int)(-1) == 0xFFFFFFFF.
    >
    > Thanks.
    >
    > Roman.
    >
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    Roman Yakovenko, Aug 13, 2003
    #1
    1. Advertising

  2. Hi Roman,

    > "Roman Yakovenko" <> schrieb im Newsbeitrag

    news:...

    > 1. Bitwise operations
    > ~210 | 118 == -129


    > I'd like to get 127 ( of course if I work within byte or smth like this ).


    I think this is a misconception! It makes no sense to use ~X without being
    aware of something like a "wordlength".
    You should use (255^X) instead

    > Today in order to get it I have to write ( ~210 | 118 ) & 0xFF


    Well.....


    > 2. Example
    > def print_selection( some_list, range=(0,-1) ):
    > lower = max( 0, range[0] )
    > upper = min( len( some_list ), unsigned_int( range[1] ) )
    > print some_list[lower:upper]


    I should not consider it good style to interpret -1 as plus infinite...

    Kindly
    Michael P.
    Michael Peuser, Aug 13, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    674
    Eric Sosman
    Jul 8, 2003
  2. sridhar

    comparing unsigned long and unsigned int

    sridhar, Nov 1, 2004, in forum: C Programming
    Replies:
    6
    Views:
    446
    J. J. Farrell
    Nov 3, 2004
  3. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,186
    Peter Shaggy Haywood
    Sep 20, 2005
  4. pereges

    Promoting unsigned long int to long int

    pereges, Jun 30, 2008, in forum: C Programming
    Replies:
    112
    Views:
    2,081
    David Thompson
    Jul 28, 2008
  5. pozz
    Replies:
    12
    Views:
    738
    Tim Rentsch
    Mar 20, 2011
Loading...

Share This Page