Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   what about unsigned and signed 8 bits number, 16 bits, etc?? (http://www.velocityreviews.com/forums/t332096-what-about-unsigned-and-signed-8-bits-number-16-bits-etc.html)

 sarmin kho 06-14-2004 01:22 PM

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

Hi Pythoners,

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

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

the python script i m working on would need to typecast the number it reads from a hardware. this number would then be typecasted according to its type before further processing. the typecasting is in form of signed 8bits and 16bits number. how do i do this in python??

many thanks
sarmin

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

 David Fisher 06-15-2004 05:42 AM

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

sarmin kho <sarmin_kho@yahoo.com> writes:

> Hi Pythoners,
>
> When it is an integer number, what is the range of the integer
> number and long integer number??
>
> do we have typecasting of 8bits or 16bits signed and unsigned number
> in python?
>
> the python script i m working on would need to typecast the number
> it reads from a hardware. this number would then be typecasted
> according to its type before further processing. the typecasting is
> in form of signed 8bits and 16bits number. how do i do this in
> python??

[...]

I did something like this in python once. I read all the hardware in
unsigned bytes then fed the resulting string into a 'struct'. Easier
for me to visualize and let the struct module workout all that byte
order cruft.

><{{{*>

 A. Lloyd Flanagan 06-15-2004 06:40 PM

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

sarmin kho <sarmin_kho@yahoo.com> wrote in message news:<mailman.937.1087219380.6949.python-list@python.org>...
> Hi Pythoners,
>
> When it is an integer number, what is the range of the integer number and
>long integer number??
>

The integer number is a C long, which is often but not always a 4-byte
value:
range: -2147483648 -- 2147483647

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

Typecasting is not necessary in Python due to the unique type system.
I believe in every case you mentioned, Python will promote the number
to a simple (signed) int.
If you need to deal directly with C types or structures, there's a
module or two for doing that.

> the python script i m working on would need to typecast the number it reads
> from a hardware. this number would then be typecasted according to its type
> before further processing. the typecasting is in form of signed 8bits and
> 16bits number. how do i do this in python??

Again, you may not have to worry about it, depending on your types.
But you can say int(x) to make an integer from x, long(x) to make a
long integer, str(x) for string, and float(x) for float.

You should read section 3.2 of the Language Reference,
http://docs.python.org/ref/types.html.

 All times are GMT. The time now is 02:08 AM.