Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: what about unsigned and signed 8 bits number, 16 bits, etc??

Reply
Thread Tools

Re: what about unsigned and signed 8 bits number, 16 bits, etc??

 
 
Miki Tebeka
Guest
Posts: n/a
 
      06-14-2004
Hello sarmin,

> When it is an integer number, what is the range of the integer number
> and long integer number??

The range of int is the same as of the machine int (the C compiler that
was used to build Python). Note that in 2.4+ int overflow will
automatically become long.
Long numbers are a big as your computer memory can handle (try 1L<<10000).

> do we have typecasting of 8bits or 16bits signed and unsigned number
> in python?

Not that I know of. I use this simple class:
class SizedNum:
def __init__(self, size, value=0):
self.mask = (1 << size) - 1
self.set(value)

def set(self, value):
self.value = value & self.mask
And also:
def sign_extend(num, size):
'''Sign exten number who is `size' bits wide'''
res = num & MASK(size - 1)
# Positive
if (num & (1L << (size - 1))) == 0:
return res

# Negative, 2's complement
res = ~res
res &= MASK(size - 1)
res += 1
return -res

HTH.

Bye.
--
-------------------------------------------------------------------------
Miki Tebeka <(E-Mail Removed)>
The only difference between children and adults is the price of the toys.

 
Reply With Quote
 
 
 
 
Marcin 'Qrczak' Kowalczyk
Guest
Posts: n/a
 
      06-14-2004
On Mon, 14 Jun 2004 16:50:36 +0200, Miki Tebeka wrote:

> The range of int is the same as of the machine int (the C compiler that
> was used to build Python).


No, Python int corresponds to C long.

--
__("< Marcin Kowalczyk
\__/ http://www.velocityreviews.com/forums/(E-Mail Removed)
^^ http://qrnik.knm.org.pl/~qrczak/

 
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
Padding bits and char, unsigned char, signed char Ioannis Vranos C Programming 6 03-29-2008 10:55 AM
Padding bits and char, unsigned char, signed char Ioannis Vranos C++ 11 03-28-2008 10:47 PM
what about unsigned and signed 8 bits number, 16 bits, etc?? sarmin kho Python 2 06-15-2004 06:40 PM
8-Bits vs 12 or 16 bits/pixel; When does more than 8 bits count ? Al Dykes Digital Photography 3 12-29-2003 07:08 PM



Advertisments