|
|
View previous topic :: View next topic |
Author |
Message |
migsantiago
Joined: 01 Apr 2006 Posts: 3
|
Data Types |
Posted: Sun Apr 02, 2006 2:29 pm |
|
|
Hello!
I was wondering which the limits were for a variable depending on its type. I looked in CCS help but I only found this:
int1
Defines a 1 bit number
int8
Defines an 8 bit number
int16
Defines a 16 bit number
int32
Defines a 32 bit number
char
Defines a 8 bit character
float
Defines a 32 bit floating point number
short
By default the same as int1
Int
By default the same as int8
long
By default the same as int16
void
Indicates no specific type
I was looking for the range that these types have; for example, int8 goes from 0 to 255.
I was told to read the file float.h but I only got some facts and I got confused
Please tell me where to find a table that includes this info.
Thanks in advance! |
|
|
Ttelmah Guest
|
|
Posted: Sun Apr 02, 2006 2:40 pm |
|
|
Use a calculator.
The size of number that an integer format can hold, is 2^n, where 'n' is the number of bits used to hold the value. So an int16, can hold 2^16 = 65536 values. You have to include '0', so the values can be 0 to 65535.
For 'signed' numbers, one bit is used to hold the sign, so a 'signed int8', can only hold 2^7 positive values.
The definition you give for 'void', is the one for C++ (where a void can be used to return any numeric type, and then converted to the required form). In CCS C, void specifically means 'no return'.
In a 'float', you have what is effectively a 24bit integer (only 23 bits are actually stored), which is then scaled by the exponent. The values in float.h, give the ranges for this. Basically you get slightly over 6 decimal digits of accuracy, scaled to cover numbers from 'FLT_MIN', up to 'FLT_MAX'.
Best Wishes |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sun Apr 02, 2006 2:43 pm |
|
|
If you are unable to count in binary you may be in for some serious problems trying to write programs...but here goes...
Basically the number of bits tells you the range:
8 bits allows you to count in binary 0-255
16 bits = 65535
32 bits - 4,294,967,295
This is for unsigned vars.
For signed variables the range is 1/2 the above and the MSB (most significant bit) is used as the sign bit to allow +/-.
Example: SIGNED 16 bit vars can hold from +32,767 down to -32,768
Here is a link to explain the ANSI C data types/byte sizes:
http://www.phim.unibe.ch/comp_doc/c_manual/C/CONCEPT/data_types.html
Keep in mind the CCS variable sizes are different than standard ANSI C as you listed earlier so you have to translate (e.g. INT in CCS is 8 bits but is 16 bits in ANSI C).
Good Luck!
EDIT: Sorry TTelmah, it seems I came I right after you did... |
|
|
migsantiago
Joined: 01 Apr 2006 Posts: 3
|
|
Posted: Sun Apr 02, 2006 9:34 pm |
|
|
Thank you guys, I also had some questions about the signs (+/-) but now they're solved. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|