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

Discussion in 'Python' started by sarmin kho, Jun 14, 2004.

  1. sarmin kho

    sarmin kho Guest

    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
    sarmin kho, Jun 14, 2004
    #1
    1. Advertising

  2. sarmin kho

    David Fisher Guest

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

    ><{{{*>
    David Fisher, Jun 15, 2004
    #2
    1. Advertising

  3. sarmin kho <> wrote in message news:<>...
    > 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.
    A. Lloyd Flanagan, Jun 15, 2004
    #3
    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. Miki Tebeka
    Replies:
    1
    Views:
    430
    Marcin 'Qrczak' Kowalczyk
    Jun 14, 2004
  2. Ioannis Vranos
    Replies:
    11
    Views:
    744
    Ioannis Vranos
    Mar 28, 2008
  3. Ioannis Vranos

    Padding bits and char, unsigned char, signed char

    Ioannis Vranos, Mar 28, 2008, in forum: C Programming
    Replies:
    6
    Views:
    599
    Ben Bacarisse
    Mar 29, 2008
  4. Rob1bureau
    Replies:
    1
    Views:
    796
    joris
    Feb 27, 2010
  5. pozz
    Replies:
    12
    Views:
    716
    Tim Rentsch
    Mar 20, 2011
Loading...

Share This Page