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

S

sarmin kho

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

any helps, please..

many thanks
sarmin

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

David Fisher

sarmin kho said:
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

A. Lloyd Flanagan

sarmin kho said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top