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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sarmin kho

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

    any helps, please..

    many thanks
    sarmin

    _______________ _______________ _______________ _____
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    Yahoo Mail: Your smarter, faster, free email solution. Organize your inbox, protect your privacy, and tackle tasks efficiently with AI-powered features and robust security tools.

  • David Fisher

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

    sarmin kho <sarmin_kho@yah oo.com> writes:
    [color=blue]
    > 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??[/color]

    [...]

    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.
    [color=blue]
    ><{{{*>[/color]

    Comment

    • A. Lloyd Flanagan

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

      sarmin kho <sarmin_kho@yah oo.com> wrote in message news:<mailman.9 37.1087219380.6 949.python-list@python.org >...[color=blue]
      > Hi Pythoners,
      >
      > When it is an integer number, what is the range of the integer number and
      >long integer number??
      >[/color]

      The integer number is a C long, which is often but not always a 4-byte
      value:
      range: -2147483648 -- 2147483647
      [color=blue]
      > do we have typecasting of 8bits or 16bits signed and unsigned number in
      >python?[/color]

      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.
      [color=blue]
      > 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??[/color]

      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.

      Comment

      Working...