Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: unsigned int \ long

Reply
Thread Tools

RE: unsigned int \ long

 
 
Roman Yakovenko
Guest
Posts: n/a
 
      08-13-2003
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 [(E-Mail Removed)]
> Sent: Wednesday, August 13, 2003 9:49 AM
> To: http://www.velocityreviews.com/forums/(E-Mail Removed)
> Subject: Re: unsigned int \ long
>
>
> look module struct -- Interpret strings as packed binary data
>
> Andres
>
> "Roman Yakovenko" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> 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
>


 
Reply With Quote
 
 
 
 
Michael Peuser
Guest
Posts: n/a
 
      08-13-2003
Hi Roman,

> "Roman Yakovenko" <(E-Mail Removed)> schrieb im Newsbeitrag

news:(E-Mail Removed) g...

> 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(int) -> (unsigned) -> (int) or (unsigned) -> (int) -> (unsigned):I'll loose something? pozz C Programming 12 03-20-2011 11:32 PM
Promoting unsigned long int to long int pereges C Programming 112 07-28-2008 05:00 AM
Having compilation error: no match for call to (const __gnu_cxx::hash<long long int>) (const long long int&) veryhotsausage C++ 1 07-04-2008 05:41 PM
unsigned long long int to long double Daniel Rudy C Programming 5 09-20-2005 02:37 AM
Assigning unsigned long to unsigned long long George Marsaglia C Programming 1 07-08-2003 05:16 PM



Advertisments