473,785 Members | 2,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
http://mail.yahoo.com
Jul 18 '05 #1
2 4358
sarmin kho <sa********@yah oo.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.
<{{{*>

Jul 18 '05 #2
sarmin kho <sa********@yah oo.com> wrote in message news:<ma******* *************** *************** @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.
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
11160
by: Peter Piper | last post by:
A Quick question if someone could help, im sure this has been asked before, but googling is getting me now where slowly. Is it possible to get an unsigned 32 bit integer field in Access. Im storing IP address in their integer form (ie. 32 bits) and Long Integer because it is signed can not represent the full range needed (0..4294967295), neither can Double. Any suggestions please?
9
4960
by: Fred Ma | last post by:
Hello, I've been trying to clear up a confusion about integer promotions during expression evaluation. I've checked the C FAQ and C++ FAQ (they are different languages, but I was hoping one would clear up the confusion), as well as googling groups and the web. The confusion is that for a binary operator,
9
4178
by: dam_fool_2003 | last post by:
For int data type the default range starts from signed to unsigned. If we don't want negative value we can force an unsigned value. The same goes for long also. But I don't understand why we have signed char which is -256. Does it means that we can assign the same ASCII value to both signed and unsigned. That means the ASCII value can be represented with a type of signed char and also unsigned char? For example int main(void) {
51
4567
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is there something wrong in there? -------------------------------------------------------------------- Types A type is a definition for a sequence of storage bits. It gives the meaning of the data stored in memory. If we say that the object a is an
23
2178
by: bjk of course | last post by:
hello, I've stumbled upon this in some code: n = !!x; I've ran it and 'n' is always either 0 or 1. Is '!!' an operator (what's it called?) and is it standard/portable? --
48
3381
by: Frederick Gotham | last post by:
The "toupper" function takes an int as an argument. That's not too irrational given that a character literal is of type "int" in C. (Although why it isn't of type "char" escapes me... ) The "toupper" function imposes a further constrait in that the value passed to it must be representable as a unsigned char. (If C does not require all character values to be positive, then again, this constrait too escapes me... ) Let's say we have the...
4
15356
by: techie | last post by:
I have defined a number of unsigned integer types as follows: typedef unsigned char uint8; typedef unsigned short uint16; typedef unsigned int uint32; typedfe long long uint64; Is it necessary to explicitly cast from one type of unsigned integer type to another even though they do so implicitly?
7
5049
by: somenath | last post by:
Hi All, I am trying to undestand "Type Conversions" from K&R book.I am not able to understand the bellow mentioned text "Conversion rules are more complicated when unsigned operands are involved. The problem is that comparisons between signed and unsigned values are machine- dependent, because they depend on the sizes of the various integer types. For example, suppose that int is 16 bits
30
4927
by: viza | last post by:
Hi all int i= INT_MIN; unsigned int u= -i; Is u guaranteed to have the absolute value of INT_MIN? Why it might not: -i has type (int), and -INT_MIN might be more than INT_MAX.
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2890
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.